我发现当您在代码中设置约束时,例如
[self.view addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[topLayoutGuide][mainView]"
options:0
metrics:nil
views:@{@"topLayoutGuide" : self.topLayoutGuide, @"mainView" : self.mainView}]];
它崩溃了:
2013-10-16 22:23:27.119 Custom Layout Guides[46840:a0b] -[LayoutGuide superview]: unrecognized selector sent to instance 0x8c80c80
2013-10-16 22:23:27.124 Custom Layout Guides[46840:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LayoutGuide superview]: unrecognized selector sent to instance 0x8c80c80'
Auto Layout 尝试调用superview
布局指南很奇怪,因为它应该只符合UILayoutSupport
协议。
我还注意到topLayoutGuide
&bottomLayoutGuide
被声明为readonly
:
@property(nonatomic, readonly, retain) id<UILayoutSupport> topLayoutGuide
@property(nonatomic, readonly, retain) id<UILayoutSupport> bottomLayoutGuide