问题描述
- 使用CAKeyframeAnimation导致导航栏的pop动画卡顿
-
我的一个提示框消失的时候,使用自定义的动画,用了CAKeyframeAnimation,此提示框消失的同时,导航栏执行pop viewcontroller操作,这时候,就出现了pop特效有卡顿的现象,如果我用UIView 的animateWithDuration 方法执行那个自定义的动画或者用uialertview代替我自己的提示框,pop特效就很流畅,这是什么原因呢?代码如下:
-(void)hideOnPopAnimation{ dispatch_async(dispatch_get_main_queue(), ^{ CAKeyframeAnimation *hideAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; hideAnimation.duration = kDefaultAnimationDuration; hideAnimation.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)], [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5,0.5 , 1.0)], [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.0, 0.0, 0.0)] ]; hideAnimation.keyTimes = @[@0.2,@0.5,@1]; hideAnimation.timingFunctions = @[[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; hideAnimation.delegate = self; hideAnimation.removedOnCompletion = NO; hideAnimation.fillMode = kCAFillModeForwards; [self.layer addAnimation:hideAnimation forKey:nil]; }); } -(void)hideOnPopAnimation{ [UIView animateWithDuration:kDefaultAnimationDuration animations:^{ self.transform = CGAffineTransformMakeScale(0.01, 0.01); } completion:^(BOOL finished) { [self destroy]; }]; }
时间: 2025-01-24 22:56:47