手动调用updateViewConstraints一个好主意? [英] Is calling updateViewConstraints manually a good idea?

查看:1694
本文介绍了手动调用updateViewConstraints一个好主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要是创造我约束 viewDidLoad中。在 updateViewConstraints 我添加或删除一些子视图,另外添加和删除约束。作为一个方面说明我使用与儿童视图控制器的容器,我对重复使用不同的方向相同的看法(全景观,在肖像酥料饼)。

I'm creating my constraints mainly in viewDidLoad. In updateViewConstraints I'm adding or removing some subviews and additionally adding and removing constraints. As a side note I'm using a container with child view controllers and I'm reusing the same view for different orientations (full in landscape, in a popover in portrait).

由于我有我的 updateViewConstraints 完整的设置我必须将它手动调用在某些情况下,以适应视觉的变化,而不是刹车的限制(例如,当presenting同样的观点在酥料饼,或在iOS 7那就不叫上旋转)。我还试图用 setNeedsUpdateConstraints 等等,但总是打破了我的限制。

Because I have my complete setup in updateViewConstraints I have to call it in some situations manually to adapt the visual changes and not to brake the constraints (e.g. when presenting the same view in a popover, or on iOS 7 it is not called on rotation). I also tried to use setNeedsUpdateConstraints and so on but that always broke my constraints.

我现在的问题是我是可以调用 updateViewConstraints 手动?它是否有一定的负面影响?或者是我的应用程序错误的流量?

My question now is am I allowed to call updateViewConstraints manually? Does it has some negative side effects? Or is the flow of my application wrong?

推荐答案

根据埃里卡丧盾中的出色的 iOS的自动布局揭秘,第2版,这是完全可以接受的调用 updateViewConstraints 直接

According to Erica Sadun in the excellent iOS Auto Layout Demystified, 2nd Edition, it's perfectly acceptable to call updateViewConstraints directly:

当与视图工作,你叫setNeedsUpdateConstraints
  (setNeedsUpdate约束:在OS X),以表明一个观点的需要
  注意在接下来的布局传递。随着视图控制器,可以调用
  updateViewConstraints方法直接,一般设置时
  (viewWillAppear中:)并响应旋转回调。

When working with views, you call setNeedsUpdateConstraints (setNeedsUpdate Constraints: on OS X) to indicate that a view needs attention at the next layout pass. With view controllers, you call the updateViewConstraints method directly, generally when setting up (viewWillAppear:) and responding to rotation callbacks.

这篇关于手动调用updateViewConstraints一个好主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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