2010-12-03 27 views
2

我试图做一个缩放环,在​​UIView的中心缩放。在UIView的中心缩放UIImageView

设置如下:

在IB,我具有连接到它的图,我的ImageView的(只是透明的PNG有环)。 设置一个IBOutlet到ImageView(theRing)和一个按钮来触发该操作。

ImageView在IB中设置为“scaleToFill”。

的动作的代码是:

-(IBAction)buttonPressed:(id)sender{ 

    CGRect theFrame = theRing.frame; 

    theFrame.size.width = 16; 
    theFrame.size.height = 16; 

    [theRing setFrame:theFrame]; //Scale down the ring first 
    theRing.center = [self.view center]; // Center the ring in the center of the view 

    theFrame.size.width = 300; 
    theFrame.size.height = 300; 

    [theRing setAlpha:1.0]; 

    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0]; 

    [theRing setFrame: theFrame]; 
    [theRing setAlpha:0.0]; 
    theRing.center = [self.view center]; 

    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector: @selector(animEnd:finished:context:)]; 
    [UIView commitAnimations]; 

} 

现在 - 当我按下按钮在第一时间,图像被缩放以基准点是所述的ImageView的左上角(手段,它缩放,但环扩展到屏幕的右下方)。

但是:当我再次按下按钮时,整个事情按预期工作(意味着,戒指停留在屏幕中间并缩放)。

任何想法?

回答

0

尝试使用ImageView的模式看点填写

+0

谢谢 - 但这并没有帮助......仍然没有在第一次尝试工作... – Swissdude 2010-12-03 22:57:40