我有四个 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){
}];
}];
我将一个动画放在下一个的完成部分。但我有 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];
}];
但无法设置两个动画之间的时间。