【发布时间】:2010-12-03 20:57:29
【问题描述】:
我正在尝试制作一个缩放环,它在 UIView 的中心进行缩放。
设置如下:
在 IB 中,我有一个视图和我的 ImageView(只是一个带环的透明 PNG)。 为 ImageView (theRing) 设置一个 IBOutlet 和一个按钮来触发操作。
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 的左上角(意味着它会缩放,但环会扩展到屏幕的右下角)。
但是:当我再次按下按钮时,整个事情都按预期工作(意味着环停留在屏幕中间并被缩放)。
有什么想法吗?
【问题讨论】:
标签: iphone uiimageview scale