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;就可以了
网友评论