UIButton
をアニメーション化することはできますか?UIButtonのアニメーション
私が自分のボタンを使ってやりたいことは、雲のように動かすことです。雲のように、指定された領域内を前後に移動します。
UIImages
をアニメーション化しようとしましたが、UIButton
もアニメーション化できるかどうかはわかりません。
UIButton
をアニメーション化することはできますか?UIButtonのアニメーション
私が自分のボタンを使ってやりたいことは、雲のように動かすことです。雲のように、指定された領域内を前後に移動します。
UIImages
をアニメーション化しようとしましたが、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)
{
}
}];
}