结束动画:animationDidStop:(CAAnimation *)anim finished:(BOOL)flag中问题

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
 animation.delegate = self;
 animation.fromValue=[NSNumber numberWithFloat:1.0];
animation.toValue=[NSNumber numberWithFloat:0.0];
animation.autoreverses= NO;
animation.duration=2.0;
animation.repeatCount= 0;
animation.fillMode=kCAFillModeForwards;
animation.removedOnCompletion=NO;
[self.view.layer addAnimation:animation forKey:@"remove"];
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
    if (flag) {
        if (anim == [self.view.layer animationForKey:@"remove"]) {
            [self.view removeFromSuperview];
        }
    }
}

注意点:
1.如果[self.view.layer animationForKey:“key”]为null。加上self.view.layer.removedOnCompletion=NO这句话就可以了。就可以通过[self.view.layer animationForKey:@“key”];”查找到对应key的animation。

2.动画连续播放中间有闪现画面,不连续。
设置一下animation.fillMode = kCAFillModeForwards;就可以了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *...
    七里田间的守望者阅读 1,444评论 0 4
  • 在iOS实际开发中常用的动画无非是以下四种:UIView动画,核心动画,帧动画,自定义转场动画。 1.UIView...
    请叫我周小帅阅读 3,142评论 1 23
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌。在这里你可以看...
    F麦子阅读 5,141评论 5 13
  • 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥ios动画全貌。在这里你可以看...
    每天刷两次牙阅读 8,551评论 6 30
  • 如果想让事情变得顺利,只有靠自己--夏尔·纪尧姆 上一章介绍了隐式动画的概念。隐式动画是在iOS平台创建动态用户界...
    夜空下最亮的亮点阅读 1,982评论 0 1