【发布时间】:2016-01-03 17:54:45
【问题描述】:
我有两个UIButton,第一个按钮将触发CustomeView 的- beginAnimation,另一个按钮将触发- endAnimation。当我依次快速按下这两个按钮时,例如begin -> end -> begin -> end -> begin -> end,我发现CADisplayLink 无法停止。更何况- rotate的射速超过了60fps,变成了60 -> 120 -> 180,就像我的主RunLoop里有不止一个CADisplaylink一样,有没有办法解决呢?而且我需要在视图的 alpha 变为零之前保持CADisplaylink 运行,所以我将[self.displayLink invalidate]; 放在完成块中,也许这会导致这个问题?
@interface CustomeView : UIView
@end
@implementation CustomeView
- (void)beginAnimation // triggered by a UIButton
{
[UIView animateWithDuration:0.5 animations:^{ self.alpha = 1.0; }];
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(rotate)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)endAnimation // triggered by another UIButton
{
[UIView animateWithDuration:0.5 animations:^{ self.alpha = 0.0; } completion:^(BOOL finished) {
[self.displayLink invalidate];
}];
}
- (void)rotate
{
// ....
}
【问题讨论】:
标签: ios cadisplaylink