簡體   English   中英

ios 8.3 NSLayoutAttributeNotAnAttribute崩潰

[英]ios 8.3 NSLayoutAttributeNotAnAttribute crash

我的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

它表示當關系沒有第二個視圖時使用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上崩潰。

我錯過了什么嗎?

您可以設置絕對高度或寬度值,在這種情況下,您將使用toItemnil和第二個attribute NSLayoutAttributeNotAnAttribute ; 但你不能設置絕對頂部。 您必須設置在相對於別的東西上-例如,相對於上海華頂(它沒有成為上海華頂,這只是一個做,所以我用它特別常見的事舉個例子)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM