NSGenericException',原因:'无法在视图上安装约束 [英] NSGenericException', reason: 'Unable to install constraint on view

查看:1129
本文介绍了NSGenericException',原因:'无法在视图上安装约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于未捕获的异常而终止应用程序'NSGenericException'

Terminating app due to uncaught exception 'NSGenericException'


由于未捕获的异常'NSGenericException'而终止应用程序,原因:'无法安装对视图的约束。约束
是否引用了视图子树之外的内容?这是
非法。约束:
查看:; layer =; contentOffset:{0,0}>'

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view. Does the constraint reference something from outside the subtree of the view? That's illegal. constraint: view:; layer = ; contentOffset: {0, 0}>'


推荐答案

你需要在两个观点中的更高。一个好的,通用的方法是这样的:

You need to install the constraint on the "higher" of the two views. A good, general way to do this is like this:

NSLayoutConstraint* constraint = ...;
NSView* firstView = constraint.firstItem;
NSView* secondView = constraint.secondItem;    
[[firstView ancestorSharedWithView: secondView] addConstraint: constraint];

请注意:这里要记住约束属性是在上下文中评估的。它们被添加的视图。因此,例如,对于viewB上安装的约束,viewA的NSLayoutAttributeLeft的值将在viewB的坐标空间中进行解释。对于仅引用同级视图或其超级视图的约束,这个事实在很大程度上是无关紧要的,但是约束不能引用两个不是兄弟或直接父母的视图。

Just a word of caution: It's good to remember here that constraint attributes are evaluated in the context of the view on which they are added. So for instance, the value of NSLayoutAttributeLeft of viewA, for a constraint installed on viewB, is interpreted in the coordinate space of viewB. For constraints that only reference sibling views or their superview, that fact is largely irrelevant, but there's no restriction that constraints can't reference two views that aren't siblings or direct parents.

这篇关于NSGenericException',原因:'无法在视图上安装约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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