Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 向哪个superview添加约束重要吗?_Ios_Cocoa Touch_Autolayout_Nslayoutconstraint - Fatal编程技术网

Ios 向哪个superview添加约束重要吗?

Ios 向哪个superview添加约束重要吗?,ios,cocoa-touch,autolayout,nslayoutconstraint,Ios,Cocoa Touch,Autolayout,Nslayoutconstraint,假设我有3种观点 A|----------| | B|-----| | | | C ▢ | | | |_____| | |__________| 如果我有一个涉及视图B和视图C的约束 建议在视图C中添加以下内容是非法的: 约束必须仅涉及接收视图范围内的视图。具体来说,涉及的任何视图都必须是接收视图本身或接收视图的子视图。添加到视图的约束称为由该视图持有。计算约束时使用的坐标系是保存约束的视图的坐标系 我是否将其添加到视图A或视图B中有关系 添加到一个superv

假设我有3种观点

 A|----------|
  | B|-----| |
  |  | C ▢ | |
  |  |_____| |
  |__________|    
如果我有一个涉及视图B和视图C的约束

建议在视图C中添加以下内容是非法的:

约束必须仅涉及接收视图范围内的视图。具体来说,涉及的任何视图都必须是接收视图本身或接收视图的子视图。添加到视图的约束称为由该视图持有。计算约束时使用的坐标系是保存约束的视图的坐标系

  • 我是否将其添加到视图A或视图B中有关系
  • 添加到一个superview而不是另一个superview有什么影响吗
  • 有什么方便的暗示吗?(例如,如果所有约束都在一个地方,则更容易管理?)
      • 将其添加到视图A或视图B并不重要,只要它们满足您从文档中引用的要求
      • 据我所知,没有任何影响,布局是相同的。根据UIView头文件中的注释(请参阅下面的摘录),约束不一定添加到您显式添加到的视图中,它们通常安装在与约束中涉及的视图最接近的祖先处(并且视图被视为其自己的祖先)
      • 这两种方法本质上都不比另一种更方便(除非您没有对a的引用,在这种情况下,将其添加到B显然更方便)。这取决于你的应用程序的设置(你有什么出口/参考等)。考虑到约束没有安装在显式添加它们的位置,这两种方法都不会更方便。不过,我认为在系统最终安装它们的地方添加它们会稍微更有效一些
      编辑:

      此注释来自UIView.h,位于用于安装约束的方法上方:

      /* 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.
       */