做了个indicator,本来以为挺简单,试了好几个方法,才最终搞定,写个博客纪念一下。
原理很简单,就是在UIWIndow上加一个View,然后上面有一个一直旋转的图片。主要问题也是出现在旋转上。
第一种方法是UIView 的animation:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationRepeatCount:INT_MAX];
[UIView setAnimationDuration:1.0f];
view.transform = CGAffineTransformMakeRotation(M_PI);
[UIView commitAnimations];
- - (void)startAnimation
- {
- CGAffineTransform endAngle = CGAffineTransformMakeRotation(imageviewAngle * (M_PI / 180.0f));
- [UIView animateWithDuration:0.01 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
- imageView.transform = endAngle;
- } completion:^(BOOL finished) {
- angle += 10; [self startAnimation];
- }];
- }
这段代码是从此处转载:http://blog.csdn.net/devday/article/details/7492469
-(CAAnimation *)animationRotate
{
CATransform3D rotationTransform3D = CATransform3DMakeRotation(M_PI, 0.0, 0, 1.0);
CABasicAnimation * animation;
animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
animation.speed = 1.5;
animation.toValue = [NSValue valueWithCATransform3D:rotationTransform3D];
animation.duration = 0.5f;
animation.autoreverses = NO;
animation.cumulative = YES;
animation.repeatCount = FLT_MAX;
animation.delegate = self;
return animation;
}