iOS 8 animation bug

Oleg Sobolev picture Oleg Sobolev · Jun 29, 2014 · Viewed 7.1k times · Source

I have a simple method for animate view.

-(void)animateSelf
{
    CABasicAnimation * animation;

    animation = [CABasicAnimation animationWithKeyPath:@"position.y"];
    // settings ...
    [self.view.layer addAnimation:animation forKey:@"position.y"];

    animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    // settings ...
    [self.view.layer addAnimation:animation forKey:@"transform.rotation.z"];

    [UIView animateWithDuration: 1.0 animations:^{
        CGRect rect = self.view.frame;
        rect.origin.y += 800;
        self.view.frame = rect;
    } completion:nil];
}

For iOS 7 it worked well. But for iOS 8 animation behaves unpredictably. Is there a way to combine these animations for iOS 8?

I tried to replace animateWithDuration: by another CABasicAnimation, but it did not help. The view.frame logs are correct, but the animation of view.frame jumps out of obscure origin.

After removing CABasicAnimation for position.y (the first one) bug is gone.

Answer

fluidsonic picture fluidsonic · Oct 7, 2014

You have three animations:

  1. You animate the layer's position
  2. You animate the layer's transform
  3. You animate the view's frame which in turn animates the layer's position.

Animations 1 and 3 collide.

  • On iOS 7 the behavior is that animation 3 cancels animation 1.
  • On iOS 8 the behavior is that animations 1 and 3 run concurrently ("Additive Animations").

I suggest you just remove animation 1 and also check out the related WWDC 2014 video (I think it was Building Interruptible and Responsive Interactions).