The first thing I would like to remove the animation creation code from the -tableView:cellForRowAtIndexPath:
method is to (say) viewDidLoad
. Then add the animation to the cell in the -tableView:cellForRowAtIndexPath:
method.
Creating objects and calculating the matrix is ββexpensive, so executing them for each call to -tableView:cellForRowAtIndexPath:
will slow down your code.
In the code, I will have something similar to the following:
- (void) viewDidLoad { // Normal viewDidLoad code above ... // Assume that rotationAnimation is an instance variable of type CABasicAnimation*; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"]; CATransform3D rotationTransform = CATransform3DMakeRotation(1.0f * M_PI, 0, 0, 1.0); rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform]; rotationAnimation.duration = 0.25f; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // create cell ... // Now apply the animation to the necessary layer. [cell.rotatingImage.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"]; return cell; }
Does it do this?
source share