是否可以对UIButton
进行动画处理?
我想要的效果是让按钮像云一样在一个给定的区域内来回移动。
我已经尝试过对UIImages
进行动画处理,但不知道UIButton
是否也可以被动画化。
是否可以对UIButton
进行动画处理?
我想要的效果是让按钮像云一样在一个给定的区域内来回移动。
我已经尝试过对UIImages
进行动画处理,但不知道UIButton
是否也可以被动画化。
正如已经提到的那样,UIButton
实例应该是可动画化的,因为它是UIView
的子类。下面的代码将使您的UIButton
来回移动,即左右移动20像素10次。基本上我将2个动画链接在一起。
- (void)startLeftRightAnimation
{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^(void)
{
[self.button setFrame:CGRectMake(self.logo.frame.origin.x-20,self.logo.frame.origin.y,self.logo.frame.size.width,self.logo.frame.size.height)];
}
completion:^(BOOL finished)
{
if(finished)
{
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^(void)
{
[self.button setFrame:CGRectMake(self.logo.frame.origin.x+40,self.logo.frame.origin.y,self.logo.frame.size.width,self.logo.frame.size.height)];
[self startLeftRightAnimation];
}
completion:^(BOOL finished)
{
if(finished)
{
}
}];
}
UIView
实例应该可以通过 [UIView animateWithDuration:animations:]
进行动画处理。由于 UIButton
是 UIView
的子类,我不预见会有任何问题...