我有两个UIViews,我想以相同的速度和同时移动.
[UIView animateWithDuration:0.25 animations:^ {
myView1.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 50.0);
myView2.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 100.0);
}];
Run Code Online (Sandbox Code Playgroud)
但是,执行上述操作意味着myView2以两倍于此速度的速度进行动画制作myView1.
如何让两个视图以相同但速度相同的方式进行动画处理(这样一个视图首先完成,然后是另一个,但是它们会同时开始制作动画)?
同时启动它们,并将动画需要两倍的时间移动两倍:
[UIView animateWithDuration:0.25 animations:^ {
myView1.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 100.0);
}];
[UIView animateWithDuration:0.5 animations:^ {
myView2.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 50.0);
}];
Run Code Online (Sandbox Code Playgroud)
基本速度数学.
另一种方法:
[UIView animateWithDuration:0.25 animations:^{
myView1.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 50.0);
myView2.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 50.0);
}
completion:^{
[UIView animateWithDuration:0.25 animations:^{
myView2.frame = CGRectMake(0.0, 0.0, 100.0, myView1.frame.size.height - 50.0);
}];
}];
Run Code Online (Sandbox Code Playgroud)
我不确定哪种方法更好或者更适合.
第一种方法使用两个单独的调用animateWithDuration,每个视图一个,其中一个在两倍的时间内动画两倍的距离(因此整体速度相同).
第二种方法使用嵌套调用来animateWithDuration通过completion块.首先,两个视图以相同的速度动画到相同的大小.接下来,需要走两倍距离的视图为剩余距离(以相同的速度)设置动画.
| 归档时间: |
|
| 查看次数: |
911 次 |
| 最近记录: |