我正在尝试在我的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];
}
有没有人知道如何解决这个问题?
非常感谢你的帮助!
答案 0 :(得分:1)
你介意尝试这个:
CGAffineTransform transform = CGAffineTransformRotate(self.smiley.transform, M_PI);
self.smiley.transform = transform;