2012-02-11 4 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) 
     { 
     } 
    }]; 
}