是NSLayoutConstraints动画? [英] Are NSLayoutConstraints animatable?

查看:182
本文介绍了是NSLayoutConstraints动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让他们被巨大的键盘横向堵塞动画一些看法。它工作得很好,如果我只是动画帧,但也有人提出,这是适得其反,我应该不是更新NSLayoutConstraints。然而,他们似乎并不为动画。有没有人得到了他们的成功合作?

I am trying to animate up some views so that they are blocked by the giant keyboard in landscape. It works well if I simply animate the frames, but others have suggested that this is counter-productive and I should be updating the NSLayoutConstraints instead. However, they don't seem to be animatable. Has anyone gotten them to work with success?

//heightFromTop is an NSLayoutConstraint referenced from IB
[UIView animateWithDuration:0.25 animations:^{
    self.heightFromTop.constant= 550.f;
}];

结果是瞬间跳转到问题的高度。

The result is an instant jump to the height in question.

推荐答案

只要按照这个确切的模式:

Just follow this exact pattern:

self.heightFromTop.constant = 550.0f;
[myView setNeedsUpdateConstraints];

[UIView animateWithDuration:0.25f animations:^{
   [myView layoutIfNeeded];
}];

其中, MyView的 self.heightFromTop 添加到视图。您的观点是跳楼,因为你的动画块做的唯一的事情就是设置限制,这不会立即导致布局。在您的code,布局发生在下次运行循环设置后, heightFromTop.constant ,到那个时候你已经是动画块的范围之外。

where myView is the view where self.heightFromTop was added to. Your view is "jumping" because the only thing you did in the animation block was to set the constraint, which does not cause layouts immediately. In your code, the layout happens on the next run loop after you set heightFromTop.constant, and by that time you are already outside the scope of the animation block.

这篇关于是NSLayoutConstraints动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆