iOS 7 Programming Pushing the Limits: Develop Advance Applications for Apple iPhone, iPad, and iPod Touch

Category: Operating Systems
Author: Mugunth Kumar, Visit Amazon's Mugunth Kumar Pagesearch resultsLearn about Author CentralMugunth Kumar
3.7
This Month Stack Overflow 1

Comments

by anonymous   2019-01-13

Core animation maintains two layer hierarchies: the model layer and the presentation layer. When the animation is in progress, the model layer is actually intact and keeps it initial value. By default, the animation is removed once the it's completed. Then the presentation layer falls back to the value of the model layer.

Simply setting removedOnCompletion to NO means the animation won't be removed and wastes memory. In addition, the model layer and the presentation layer won't be synchronous any more, which may lead to potential bugs.

So it would be a better solution to update the property directly on the model layer to the final value.

self.view.layer.opacity = 1;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = 0;
animation.toValue = 1;
[self.view.layer addAnimation:animation forKey:nil];

If there's any implicit animation caused by the first line of above code, try to turn if off:

[CATransaction begin];
[CATransaction setDisableActions:YES];

self.view.layer.opacity = 1;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.fromValue = 0;
animation.toValue = 1;
[self.view.layer addAnimation:animation forKey:nil];

[CATransaction commit];
by anonymous   2018-03-05
I wrote a lot about UIKitDynamics when it first came out. I'm not aware of a lot of other materials on it. If it does interest you, see https://www.amazon.com/iOS-Programming-Pushing-Limits-Applications/dp/1118818342 (which is where the sample code comes from).