iOS:Autolayout 不适用于动画

标签 ios autolayout uiviewanimation

在我的应用程序中,我有一个 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/

相关文章:

ios - 使用自动布局时如何在加载时滚动 UIScrollView

ios - 自动布局 : Location anchors require being paired 崩溃

ios - 如何为 UISearchbar 框架更改设置动画以保持圆角?

iphone - 如何更改表格 View 中心标签突出显示?

ios - 确定 CATextLayer 中文本框的大小

ios - Bluetooth LE (4.0) 有多少个中心可以连接到外围设备?

iphone - uitableview 中返回的单元格数

ios - 同一系列和方向的设备的自动布局问题

objective-c - UIView 动画 block 与 CAAnimation

ios - 将框架设置为 UIView 不起作用