在我的应用程序中,我有一个 Storyboard,我使用了“autolayout”选项;问题是如果我以这种方式移动一些带有动画的 UIImageView:
[UIView animateWithDuration:1.0 animations:^{
[image setCenter:CGPointMake(300,200)];
}];
当动画结束图像回到原来的位置时,为什么???如果我不检查自动版式选项它工作正常。 你能告诉我是否可以使用自动布局管理动画吗?以及如何做到这一点?
最佳答案
自动布局的第一条规则! 您无法使用自动布局更改 View 的框架或中心。
为了对 View 进行动画处理,您必须设置一个用于对其进行动画处理的约束,然后更改该约束。
即
self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.theView
attribute:
relatedBy:
toItem:
attribute:
multiplier:
constant:];
// set up the rest
[self.view addConstraint:self.heightConstraint];
然后为其设置动画...
self.heightConstraint.constant = 20;
[UIView animateWithDuration:2.0
animations:^() {
[self.view layoutIfNeeded];
}];
关于iOS:Autolayout 不适用于动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21385211/