转载自:http://blog.youkuaiyun.com/zhibudefeng/article/details/8691567
CABasicAnimation *rotationAnimation = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumbernumberWithFloat:2*M_PI*0.722];
rotationAnimation.duration = 1.0f;
rotationAnimation.repeatCount = MAXFLOAT;
rotationAnimation.autoreverses = YES;
rotationAnimation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.pointerImageView.layeraddAnimation:rotationAnimation forKey:nil];
用下面这种方法则只会花半个圆:
CGAffineTransform transform;
transform = CGAffineTransformRotate(self.pointerImageView.transform,2*M_PI*0.722);
[UIView beginAnimations:@"rotate" context:nil ];
[UIViewsetAnimationDuration:2];
[UIViewsetAnimationDelegate:self];
[self.pointerImageView setTransform:transform];
[UIView commitAnimations];
如果想动画执行一次后停止在当前位置 ,则应该这么做:
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat:2*M_PI*0.722];
rotationAnimation.duration = 1.5f;
rotationAnimation.repeatCount = 0;
rotationAnimation.autoreverses = NO;
rotationAnimation.removedOnCompletion = NO; //要实现完成动画后停止在当前位置 这个值应该设置成NO 然后下边的kCAFillModeForwards这个才会起作用
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.delegate = self;
rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.pointerImageView.layer addAnimation:rotationAnimation forKey:@"KeyStartSwing"];