作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的 NSLayoutConstraint 遇到了一个奇怪的问题。
我最近将我的 iPhone 更新到 8.3 并使用最新的 Xcode。
该应用程序在 iOS 8.3 上崩溃,断点指向我:
self.triangleTopConstraint = [NSLayoutConstraint constraintWithItem:self.triangle
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0.0];
[self addConstraint:self.triangleTopConstraint];
这在 iOS 8.3 之前有效。
但是,我在这里阅读了此页面:
它说当关系没有第二个 View 时使用 NSLayoutAttributeNotAnAttribute
。所以我把它改成这样:
self.triangleTopConstraint = [NSLayoutConstraint constraintWithItem:self.triangle
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0
constant:0.0];
[self addConstraint:self.triangleTopConstraint];
但该应用程序在 iOS 8.3 上仍然崩溃。
我错过了什么吗?
最佳答案
您可以设置绝对高度或宽度值,在这种情况下,您可以使用 nil
的 toItem
和第二个 attribute
NSLayoutAttributeNotAnAttribute
;但您不能设置绝对顶部。您必须设置顶部相对于其他东西——例如,相对于父 View 的顶部(它不是必须是父 View 的顶部,这是一件特别常见的事情,所以我以它为例)。
关于ios 8.3 NSLayoutAttributeNotAnAttribute 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29641579/
我的 NSLayoutConstraint 遇到了一个奇怪的问题。 我最近将我的 iPhone 更新到 8.3 并使用最新的 Xcode。 该应用程序在 iOS 8.3 上崩溃,断点指向我: self
我是一名优秀的程序员,十分优秀!