長押しすると回転を開始するシンプルな UILabel があります。次のコードを使用して、これを正常に達成しています。
-(IBAction)longPressEffect:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
UIViewAnimationOptions animationOptions = UIViewAnimationCurveLinear | UIViewAnimationOptionRepeat;
[UIView animateWithDuration:0.4 delay:0.0 options:animationOptions animations:^ {
labelObject.transform = CGAffineTransformMakeRotation(DegreesToRadians(angle));
} completion:nil];
angle = angle + 180;
}
else if (sender.state == UIGestureRecognizerStateEnded) {
;
}
}
ユーザーは、ラベルをダブルクリックするだけで、いつでもこのアニメーションを停止できます。そのためのコードは次のとおりです。
-(IBAction)doubleTapEffect:(UITapGestureRecognizer *)sender {
[labelObject.layer removeAllAnimations];
labelObject.transform = CGAffineTransformMakeRotation(DegreesToRadians(0));
}
問題は、次にラベルを長押ししたときに応答しないことです。回転アニメーションが再起動しません。再度実行するには、もう一度クリックする必要があります。
したがって、パターンは次のとおりです
。1) 長押し - アニメーションの開始
2) ダブルクリック - アニメーションの停止
3) 長押し -何も起こらない
4) もう一度長押し - アニメーションが再び開始されます。
これを修正するにはどうすればよいですか?