我正在尝试从上到下制作视图幻灯片。这没什么大不了的,我用CABasicAnimation
这个。问题是当我想删除视图时。我用这个动画。
CABasicAnimation *animation;
animation = [CABasicAnimation animationWithKeyPath:@"position"];
[animation setDelegate:self];
animation.toValue = [NSValue valueWithCGPoint:CGPointMake(self.view.layer.position.x, 0 - self.view.bounds.size.height / 2)];
animation.fromValue = [NSValue valueWithCGPoint:self.view.layer.position];
animation.autoreverses = NO;
animation.repeatCount = 0;
animation.duration = 0.25;
animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
[self.view.layer addAnimation:animation forKey:@"moveX"];
完美地为视图设置动画。但是,动画结束后,我的视图又出现了。所以我添加了这一行:
[self.view removeFromSuperview];
这会删除视图,但没有动画。所以我决定将删除代码添加到这个委托:
-(void) animationDidStop:(CAAnimation *) animation finished:(bool) flag
所以现在,动画起作用了,视图消失了,但有时,我可以看到视图出现和消失的速度更快,就像动画之后,视图出现,然后animationDidStop
调用委托,视图消失,显然这很糟糕。我究竟做错了什么?