2012-02-11 60 views
3

是否可以动画UIButton动画UIButton

我想用我的按钮做的动画就像一个云,它只能在给定区域来回移动。

我试过动画UIImages,但我不知道UIButton也可以动画。

回答

3

UIView实例应具有动画效果,可使用[UIView animateWithDuration:animations:]。由于UIButtonUIView一个子类,我不预见任何问题......

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) 
     { 
     } 
    }]; 
}