Refresh animation on UIBarButtonItem

送分小仙女□ 提交于 2020-01-05 08:15:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!