问题
I am trying to make a "refresh" animation using a UIBarButtonItem, the problem is that is not only rotating but moving the image up and down a bit.
-(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];
}
回答1:
Check the image, make sure that the image's center is in the center of the spinner (because it looks like it most likely isn't). Go into your favourite image editing software and center it, making sure that when you export, the transparent areas aren't clipped off.
来源:https://stackoverflow.com/questions/29560609/refresh-animation-on-uibarbuttonitem