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

问题描述

让说我有3次

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

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

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

的文档建议增加视图C将是非法的:

The documentation suggests adding to view C would be illegal:

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


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

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

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

推荐答案


  • 如果你把它添加到视图A或查看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.
  • 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).
  • 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我加约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:06