不要紧,它的SuperView我加约束? [英] Does it matter which superview I add constraints to?

查看:197
本文介绍了不要紧,它的SuperView我加约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让说我有3次

 A|----------|
  | B|-----| |
  |  | C ▢ | |
  |  |_____| |
  |__________|    

如果我有涉及视图B中的约束,并查看C.

If I have a constraint involving view B and view C.

的<一个href=\"http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/addConstraint%3a\"相对=nofollow>文档建议增加视图C将是非法的:

The documentation suggests adding to view C would be illegal:

约束必须包括仅接收视图范围内的意见。具体来说,所涉及的任何意见必须是接收视图本身,或者接收视图的子视图。被添加到一个视图约束据说是由该视图举行。评估约束时使用的坐标系是保存约束视图的坐标系。

The constraint must involve only views that are within scope of the receiving view. Specifically, any views involved must be either the receiving view itself, or a subview of the receiving view. Constraints that are added to a view are said to be held by that view. The coordinate system used when evaluating the constraint is the coordinate system of the view that holds the constraint.


  • 不要紧,如果我把它添加到浏览A或视图B?

  • 是否有添加一个上海华而不是其他任何影响?

  • 有没有什么方便的意义? (例如,它更容易管理,如果所有约束在一个地方?)

推荐答案


  • 如果你把它添加到视图A或查看B,所以只要符合你的文件引述的要求没关系。

  • <击>有没有我所知道的任何影响,布局是一​​样的两种方式。的约束不一定添加到视图您明确将它们添加到,根据该意见UIView的头文件(见下文节选)它们通常安装在最近的祖先给参与约束的意见(和一个视图被认为是其自己的这个祖先)。

  • <击>既不方式比其他本质上更方便的(除非你没有一个参考的一种,在这种情况下,显然是更方便的,将其添加到B)。这将取决于你的应用程序的安装(你有网点/参考文献等)。鉴于约束不是安装在你明确地添加他们,既没有办法将更加方便。我想这是稍微更有效地将它们添加其中系统将最终安装它们,虽然。

  • It does not matter if you add it to view A or to view B, so long as they meet the requirements you quoted from the documentation.
  • There are not any implications that I am aware of, the layout is the same either way. The constraints are not necessarily added to the view that you explicitly add them to, according to the comments in the UIView header file (see excerpt below) they are typically installed at the closest ancestor to the views involved in the constraint (and a view is considered to be its own ancestor for this).
  • Neither way is inherently more convenient than the other (unless you don't have a reference to A, in which case it is obviously more convenient to add it to B). It would depend on the setup of your application (what you have outlets for/references to, etc). Given that the constraints are not installed where you explicitly add them, neither way would be more convenient. I would suppose it to be slightly more efficient to add them where the system will install them ultimately, though.
  • 编辑:

    这个评论是从UIView.h,上述方法用于安装的限制:

    This comment is from UIView.h, above the methods used to install constraints:

    /* A constraint is typically installed on the closest common ancestor of the views involved in the constraint. 
     It is required that a constraint be installed on _a_ common ancestor of every view involved.  The numbers in a constraint are interpreted in the coordinate system of the view it is installed on.  A view is considered to be an ancestor of itself.
     */
    

    这篇关于不要紧,它的SuperView我加约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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