是否可以为UIButton
设置动画?
我想用我的按钮做的就是将它设置为像云一样的动画,它只在给定区域内来回移动。
我已尝试动画UIImages
,但我不知道UIButton
是否也可以设置动画。
答案 0 :(得分:3)
UIView
实例应该可以使用[UIView animateWithDuration:animations:]
设置动画。由于UIButton
是UIView
的子类,我预见不会有任何问题......
答案 1 :(得分:3)
正如已经说过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)
{
}
}];
}