7

我一直在尝试创建一个容器视图控制器,它提供一些覆盖视图,如 UINavigationController 和 UITabBarController 为 iOS 7 中的视图控制器做的。为了使包含的视图布局正确,我已经尝试了几乎所有我能想到的关于实现-bottomLayoutGuide 在容器和包含的视图控制器中,但没有运气。该方法被调用,但该值似乎没有被使用。

我在https://github.com/stefanfisk/custom-layout-guides整理了一个简单的示例,但我什至无法调用访问器。

4

1 回答 1

2

我发现当您在代码中设置约束时,例如

[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
于 2013-10-16T20:26:22.287 回答