动画autolayout`leftAnchor`约束更改

时间:2017-05-19 23:25:31

标签: ios objective-c autolayout nslayoutconstraint

我有一个UIView,我正在初始化以启动' offscreen'在视图的右侧占100%。我通过以下方式做到这一点:

[UIView animateWithDuration: 5
                 animations: ^{
                     [childView.leftAnchor constraintEqualToAnchor: superview.leftAnchor
                                                               constant: 1.0].active = YES;
                 }];

然后我想滑动'左边的视图。我想也许会做以下事情:

{{1}}

可能会这样做,但它会立即发生(没有动画,它只会出现')。

是否可以使用自动布局锚点来提供动画?

1 个答案:

答案 0 :(得分:1)

[childView.leftAnchor constraintEqualToAnchor: superview.leftAnchor constant: 1.0].active = YES;
[UIView animateWithDuration: 5
                 animations: ^{
                     [childView layoutIfNeeded];
                 }];

这应该这样做。约束更改本身不应该在动画块中,只是布局调用。您还应该禁用/删除您所做的初始约束,因为这个新约束与它直接冲突(您可能会在控制台中看到警告)。

相关问题