开发者

Update UIImageView while cycle running

开发者 https://www.devze.com 2023-01-23 17:15 出处:网络
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGFloat coef = tempCount / 20; while(tempCount >= 0)
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 CGFloat coef = tempCount / 20;
 while(tempCount >= 0)
 {
  [imgView setTransform: CGAffineTransformRotate([imgView transform], -1*coef)];
  tempCount -=coef;
  [NSThread sleepForTimeIn开发者_开发技巧terval: 0.09];
 }
}

And the problem is in than, that my image on the image view updates only after cycle. I want it to update every 0.09 seconds. What can you propose? Thanx!


If you want to rotate a view with animation use animation facilities SDK provides for you. To rotate your view on full 360 degrees you will need to use core animation.

The following code will rotate your view during 3 sec:

#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"];

Or try the following - I have not tested the code, but it should reset view's transform to identity with animation:

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

[imgView setTransform:CGAffineTransformIdentity];

[UIView commitAnimations];
0

精彩评论

暂无评论...
验证码 换一张
取 消