Skip to content

Instantly share code, notes, and snippets.

@meiwin
Created February 13, 2012 09:49
Show Gist options
  • Save meiwin/1815541 to your computer and use it in GitHub Desktop.
Save meiwin/1815541 to your computer and use it in GitHub Desktop.
CALayer animation (the correct way)
// sample codes for animating calayer's opacity
CABasicAnimation * animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = [NSNumber numberWithValue:0];
animation.toValue = [NSNumber numberWithValue:1];
targetLayer.opacity = 1; // must be set, otherwise targetLayer opacity will not be updated, even after animation is completed.
[targetLayer addAnimation:animation forKey:@"opacity"]; // the key "opacity" must match keyPath being animated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment