【发布时间】:2014-06-02 04:39:12
【问题描述】:
我有一个 CALayer,我想显示它然后隐藏它。
CALayer *layerOne = [CALayer layer];
[layerOne addSublayer:textOne];
layerOne.frame = CGRectMake(0, 0, size.width, size.height);
[layerOne setMasksToBounds:YES];
layerOne.opacity = 0.0;
CABasicAnimation *animationOne = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animationOne setDuration:0];
[animationOne setFromValue:[NSNumber numberWithFloat:0.0]];
[animationOne setToValue:[NSNumber numberWithFloat:1.0]];
[animationOne setBeginTime:3];
[animationOne setRemovedOnCompletion:NO];
[animationOne setFillMode:kCAFillModeForwards];
[layerOne addAnimation:animationOne forKey:@"animateOpacity"];
此代码运行成功,layerOne 在 3 秒后出现。
但是我想隐藏这个层,所以我添加了这个:
CABasicAnimation *animationTwo = [CABasicAnimation animationWithKeyPath:@"opacity"];
[animationTwo setDuration:0];
[animationTwo setFromValue:[NSNumber numberWithFloat:1.0]];
[animationTwo setToValue:[NSNumber numberWithFloat:0.0]];
[animationTwo setBeginTime:6];
[animationTwo setRemovedOnCompletion:NO];
[animationTwo setFillMode:kCAFillModeForwards];
[layerOne addAnimation:animationTwo forKey:@"animateOpacity"];
而且它不起作用。 layerOne 3 秒后没有出现。它只是在第 6 秒闪过然后消失了。似乎第二个动画阻止了第一个动画,只有第二个动画在播放。
我做错了什么?
【问题讨论】:
标签: ios calayer cabasicanimation caanimation