3

4 つの UIbuttons があり、それらの x 原点を変更する必要があります。今ではこの方法を使用しています:

[UIView animateWithDuration:1.0
                          delay:1.0
                        options: UIViewAnimationCurveEaseInOut
                     animations:^{

                     self.Button1.frame = CGRectMake(-120, self.Button1.frame.origin.y, self.Button1.frame.size.width, self.Button1.frame.size.height);

                     }
                     completion:^(BOOL finished){

                        [UIView animateWithDuration:1.0
                          delay:1.0
                        options: UIViewAnimationCurveEaseInOut
                     animations:^{

                     self.Button1.frame = CGRectMake(-140, self.Button1.frame.origin.y, self.Button1.frame.size.width, self.Button2.frame.size.height);

                     }
                     completion:^(BOOL finished){


                     }];
                     }];

次の完成セクションに 1 つのアニメーションを入れています。しかし、私は4/5ボタンを持っています。私はこれを何度も行うことはできません。オブジェクトでアニメーションを実行し、0.5 秒後に次のオブジェクトでアニメーションを実行する方法はありますか?

編集:

私はこれを使用しようとしました:

typedef void (^AnimationBlock)();

AnimationBlock firstAnimation = ^{ self.Button1.frame = CGRectMake(-120, self.Button1.frame.origin.y, self.Button1.frame.size.width, self.Button1.frame.size.height); };

AnimationBlock secondAnimation = ^{ self.Button4.frame = CGRectMake(-120, self.Button4.frame.origin.y, self.Button4.frame.size.width, self.Button4.frame.size.height);};

[UIView animateWithDuration:2 animations:firstAnimation completion:^(BOOL finished) {
    [UIView animateWithDuration:2 animations:secondAnimation];
}];

ただし、2 つのアニメーション間の時間を設定することはできません。

4

2 に答える 2

2

私がすることは、あなたが持っているコードを取り、それをより一般的なものにすることです. 次に、任意のボタンを任意の遅延で簡単にアニメーション化できます。

- (void)animateButton:(UIButton *)button toRect:(CGRect)rect1 thenToRect:(CGRect)rect2 withDelay:(CGFloat)delay
{
    [UIView animateWithDuration:1.0
                          delay:delay
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         button.frame = rect1;
                     }
                     completion:^(BOOL finished){
                        [UIView animateWithDuration:1.0
                                              delay:delay
                                            options:UIViewAnimationCurveEaseInOut
                                         animations:^{
                                             button.frame = rect2;
                                         }
                                         completion:nil];
                     }];
}

次に、次のように使用します(rect作成コードを単純化して、きれいにしました)

[self animateButton:self.button1
             toRect:CGRectOffset(self.button1.frame, -120 - self.button1.frame.origin.x)
         thenToRect:CGRectOffset(self.button1.frame, -140 - self.button1.frame.origin.x)
              delay:0.5f];
于 2013-08-27T16:27:36.113 に答える