我正在尝试在我的 iOS 应用程序上设置动画。这个想法是让自定义 UIButton 旋转得非常快,以很好地改变它的图片。基本上我有两个形状相同但图标不同的 UIButton。当我让键盘出现时,我让顶部的一个旋转并淡出,而另一个旋转然后停止。
当我让键盘消失时,我想触发相同的动画,但反过来。
我的问题是我的两个按钮只旋转一次。我无法设法让它们以任何其他方式旋转。
这是我的代码:
- (void) textFieldDidBeginEditing:(UITextField *)myTextField{
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
self.main.transform = transform;
}
completion:^(BOOL finished){
}];
[UIView animateWithDuration:0.3 animations:^{
[UIView setAnimationDelay:0.0];
self.main.alpha = 0.0;
}];
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI);
self.smiley.transform = transform;
} completion:^(BOOL finished){
}];
[self animateTextField:myTextField up:YES];
}
- (void) textFieldDidEndEditing:(UITextField *)myTextField{
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
self.smiley.transform = transform;
} completion:NULL];
[UIView animateWithDuration:0.3 animations:^{
self.main.alpha = 1.0;
}];
[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[UIView setAnimationRepeatCount:3];
CGAffineTransform transform = CGAffineTransformMakeRotation(-M_PI);
self.main.transform = transform;
} completion:^(BOOL finished){
}];
[self animateTextField:myTextField up:NO];
}
有谁知道如何解决这个问题?
非常感谢您的帮助!