ボタンジグルアニメーションを完成させました。ボタンを押すとぐらつきますが、問題はアニメーションが停止せず、[self.layerremoveAllAnimations]でエラーが発生することです。以下はコードです。
-(IBAction)button1Clicked:(id)sender
{
UIButton *no1 =sender;
output= [self answerCheck:no1.titleLabel.text];
self.label.text=output;
[self enableOptions:NO];
[self loadingView];
[self startJiggling:2];
}
- (void)startJiggling:(NSInteger)count
{
CGAffineTransform leftWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? +1 : -1 ) ));
CGAffineTransform rightWobble = CGAffineTransformMakeRotation(degreesToRadians( kAnimationRotateDeg * (count%2 ? -1 : +1 ) ));
CGAffineTransform moveTransform = CGAffineTransformTranslate(rightWobble, -kAnimationTranslateX, -kAnimationTranslateY);
CGAffineTransform conCatTransform = CGAffineTransformConcat(rightWobble, moveTransform);
self.btnOption1.transform = leftWobble; // starting point
[UIView animateWithDuration:0.1
delay:(count * 0.08)
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{ self.btnOption1.transform = conCatTransform; }
completion:nil];
[self stopJiggling];
}
-(void)stopJiggling
{
[self.btnOption1.layer removeAllAnimations];
self.btnOption1.transform = CGAffineTransformIdentity; // Set it straight
}