1

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.

enter image description here

-(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];
}
rckoenes
  • 69,092
  • 8
  • 134
  • 166
apinho
  • 2,235
  • 3
  • 25
  • 39

1 Answers1

3

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.

Schemetrical
  • 5,506
  • 2
  • 26
  • 43
  • Well I used the system one and had the same problem! – apinho Apr 10 '15 at 12:54
  • UIBarButtonItem *refreshBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(navigationBarRefreshButtonTapped)]; [self.navigationItem setRightBarButtonItem:refreshBarButtonItem]; – apinho Apr 10 '15 at 12:54