我试图动画从位置A到B然后再返回的视图.以前,我会做以下的动画来制作B:
[UIView animateWithDuration:1 animations:^{
self.myView.transform = CGAffineTransformMakeTranslation(100, 0);
}];
Run Code Online (Sandbox Code Playgroud)
然后这将动画回到A:
[UIView animateWithDuration:1 animations:^{
self.myView.transform = CGAffineTransformMakeTranslation(0, 0);
}];
Run Code Online (Sandbox Code Playgroud)
所有这些都无需了解原始位置.
现在在自动布局中我使用以下代码动画到位置B:
self.myLeadingConstraint.constant = 100;
[UIView animateWithDuration:1 animations:^{
[self.view layoutIfNeeded];
}];
Run Code Online (Sandbox Code Playgroud)
有没有办法获得以前的常量值而无需创建另一个变量或查看IB以查看初始值是什么?有没有更好的方法来做所有这些?
提前致谢.
不,这是最简单的方法.以下是动画自动布局的选项:
你的意思是获得前一个恒定值?是不是在self.myLeadingConstraint.constant上呢?
| 归档时间: |
|
| 查看次数: |
1279 次 |
| 最近记录: |