Skip to content

Instantly share code, notes, and snippets.

@d-ronnqvist
Created September 6, 2014 15:39
Show Gist options
  • Save d-ronnqvist/137ce6b4c852d8ebd96d to your computer and use it in GitHub Desktop.
Save d-ronnqvist/137ce6b4c852d8ebd96d to your computer and use it in GitHub Desktop.

The UIView animation API results in different CAAnimations being added to the layer on iOS 7 and 8. Changing the bounds of a view like this:

[UIView animateWithDuration:0.3 
                 animations:^{
    self.myView.bounds = CGRectMake(0, 0, 100, 100); // was (0,0) (200, 200)
}];

will result in one animation for the bounds key path being added to the backing layer if you are running iOS 7:

<CABasicAnimation:0x7fdefbd1dbf0; 
  delegate = <UIViewAnimationState: 0x7fdefbd17d60>; 
  fillMode = both; 
  timingFunction = easeInEaseOut; 
  duration = 0.3; 
  fromValue = NSRect: {{0, 0}, {200, 200}}; 
  keyPath = bounds
>

but will result in two different animations for bounds.origin and bounds.size being added if you are running iOS 8:

<CABasicAnimation:0x7f908b529c40; 
  toValue = NSPoint: {0, 0};
  additive = 1;
  fromValue = NSPoint: {0, 0};
  keyPath = bounds.origin; 
  delegate = <UIViewAnimationState: 0x7f908b525e70>;
  fillMode = both; 
  timingFunction = easeInEaseOut; 
  duration = 0.3
>
<CABasicAnimation:0x7f908b5244c0; 
  toValue = NSSize: {0, 0}; 
  additive = 1; 
  fromValue = NSSize: {100, 100}; 
  keyPath = bounds.size;
  delegate = <UIViewAnimationState: 0x7f908b525e70>;
  fillMode = both;
  timingFunction = easeInEaseOut;
  duration = 0.3
>

Looking at how the animations are configured, this has to do with the way that the UIView animation API creates additive animations in iOS 8.

@KevinDoughty
Copy link

Rect animation enforces absolute values for width and height. Fortunately size animation doesn't. With additive animation, there is a need for negative width and height values, so two animations are used. Amusingly, this workaround was not needed in 10.5 Leopard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment