UIButton
最初のボタンは CustomeView をトリガーし- beginAnimation
、もう 1 つのボタンは をトリガーします- endAnimation
。この 2 つのボタンを のようにすばやく交互に押すと、停止できないことがbegin -> end -> begin -> end -> begin -> end
わかりました。CADisplayLink
さらに、- rotate
の連射速度は 60fps を超えており、私のメインの RunLoop に60 -> 120 -> 180
複数あるように になりました。それを修正する方法はありますか? CADisplaylink
そして、ビューのアルファがゼロになる前に実行を続ける必要があるため、完了ブロックCADisplaylink
に を入れました[self.displayLink invalidate];
。これがこの問題を引き起こすのではないでしょうか?</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
{
// ....
}