![](/img/trans.png)
[英]iOS8 Beta 3 UITableViewCell layoutSubviews infinite loop
[英]How to get constraints is ios8 before layoutSubviews?
我有一個視圖是UIView的子類,當我在xib中添加約束時,現在我應該嘗試獲取數組約束,但是iOS 7和iOS 8有所不同。它適用於iOS 7,而iOS 8是無效。
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
NSLog(@"constraints = %@",self.constraints);
}
return self;
}
是否為xib關閉了AutoLayout?
如果我拿一個項目,並在iOS8上運行它,並且關閉了自動布局,則會得到:
2015-04-29 00:30:48.796 simpletest[37423:4105842] constraints = (
)
如果重新打開自動版式,則會得到約束列表:
2015-04-29 00:32:03.755 simpletest[37448:4107364] constraints = (
"<NSLayoutConstraint:0x7a694c90 V:[_UILayoutGuide:0x7a87f280]-(0)-[UIButton:0x7a6834a0'Another View']>",
"<NSLayoutConstraint:0x7a691b90 UIButton:0x7a6834a0'Another View'.leading == UIView:0x7a87ef50.leadingMargin>",
"<NSLayoutConstraint:0x7a6871c0 V:[UIButton:0x7a6834a0'Another View']-(100)-[UIView:0x7a87f0f0]>",
"<NSLayoutConstraint:0x7a696670 UIView:0x7a87f0f0.leading == UIView:0x7a87ef50.leadingMargin + 30>",
"<NSLayoutConstraint:0x7a691bf0 UIView:0x7a87ef50.trailingMargin == UIView:0x7a87f0f0.trailing + 30>",
"<NSLayoutConstraint:0x7a686620 V:[UIView:0x7a87f0f0]-(100)-[_UILayoutGuide:0x7a87f950]>",
"<_UILayoutSupportConstraint:0x7a68d8f0 V:[_UILayoutGuide:0x7a87f280(0)]>",
etc.
啟用或禁用自動版式設置的復選框在此圖像的底部附近:
重新閱讀您的文章,看來您實際上是在添加一些約束,而如果您禁用了自動版式,則無法做到。 因此,也許這不是您的問題。 但是,從我的輸出中可以看到,當存在約束時,iOS8不會為self.constraints返回nil。
首先,您應該考慮將邏輯移至awakeFromNib。 這是所有筆尖/ xib的起點。 例如,initWithCoder尚未加載IBOutlets。
其次,請記住,當您添加相對於其他同級的約束時,父級就是持有約束的那個。 因此,如果A對B具有水平約束,則該約束將在A.superview.constraints中。
但是,如果A具有不基於其他視圖(例如高度或寬度)的約束,則可以在A.constraints中找到它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.