我试图让使用的UIBarButtonItem一个“刷新”动画,问题是,不仅旋转而且移动图像上下位。
-(void)startRefreshButtonRotationAnimation {
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0];
rotationAnimation.duration = 1;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1000;
UIView *view = self.navigationItem.rightBarButtonItem.customView;
[view.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
- (void)stopRefreshButtonRotationAnimation {
UIView *view = self.navigationItem.rightBarButtonItem.customView;
[view.layer removeAllAnimations];
}