我有两个UIButton
,第一个按钮将触发 CustomeView - beginAnimation
,另一个按钮将触发- endAnimation
. 当我依次快速按下这两个按钮时begin -> end -> begin -> end -> begin -> end
,我发现CADisplayLink
停不下来。更何况 的- rotate
射速超过 60fps,变成60 -> 120 -> 180
了 ,就像CADisplaylink
我的主 RunLoop 里有不止一个,那么有没有办法修复它?而且我需要CADisplaylink
在view的alpha归零之前保持运行,所以我把它[self.displayLink invalidate];
放在了completion block中,可能会导致这个问题?</p>
@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
{
// ....
}