gpt4 book ai didi

ios 8.3 NSLayoutAttributeNotAnAttribute 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:45:38 25 4
gpt4 key购买 nike

我的 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 之前有效。

但是,我在这里阅读了此页面:

https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/#//apple_ref/c/tdef/NSLayoutAttribute

它说当关系没有第二个 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 上仍然崩溃。

我错过了什么吗?

最佳答案

您可以设置绝对高度或宽度值,在这种情况下,您可以使用 niltoItem 和第二个 attribute NSLayoutAttributeNotAnAttribute;但您不能设置绝对顶部。您必须设置顶部相对于其他东西——例如,相对于父 View 的顶部(它不是必须是父 View 的顶部,这是一件特别常见的事情,所以我以它为例)。

关于ios 8.3 NSLayoutAttributeNotAnAttribute 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29641579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com