循环运行时更新UIImageView

时间:2010-11-02 12:28:57

标签: iphone cocoa-touch uiimageview

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 CGFloat coef = tempCount / 20;
 while(tempCount >= 0)
 {
  [imgView setTransform: CGAffineTransformRotate([imgView transform], -1*coef)];
  tempCount -=coef;
  [NSThread sleepForTimeInterval: 0.09];
 }
}

问题在于,我的图像视图上的图像仅在循环后更新。我希望它每0.09秒更新一次。你能提出什么建议?感谢名单!

1 个答案:

答案 0 :(得分:0)

如果要使用动画使用动画设施旋转视图,SDK会为您提供。要在360度全方位旋转视图,您需要使用核心动画。

以下代码将在3秒内旋转您的视图:

#import <QuartzCore/QuartzCore.h>
...
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat: 2*M_PI];
animation.duration = 3.0f;
animation.repeatCount = 1.0f;
[imgView.layer addAnimation:animation forKey:@"MyAnimation"];

或者尝试以下操作 - 我没有测试过代码,但它应该将视图的转换重置为动画的身份:

[UIView beginAnimations:@"Reset dial" context: nil];
[UIView setAnimationDuration: 1.0f];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];

[imgView setTransform:CGAffineTransformIdentity];

[UIView commitAnimations];