动画UIButton
答
UIView
实例应具有动画效果,可使用[UIView animateWithDuration:animations:]
。由于UIButton
是UIView
一个子类,我不预见任何问题......
答
前面已经说过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)
{
}
}];
}