是否可以在UIViewController的子条款中实现topLayoutGuide和bottomLayoutGuide?

Ste*_*isk 7 uiviewcontroller autolayout ios7

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

我在https://github.com/stefanfisk/custom-layout-guides上放了一个简单的例子,但在那里我甚至无法调用访问器.

Are*_*lko 2

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

[self.view addConstraints:[NSLayoutConstraint
                           constraintsWithVisualFormat:@"V:[topLayoutGuide][mainView]"
                           options:0
                           metrics:nil
                           views:@{@"topLayoutGuide" : self.topLayoutGuide, @"mainView" : self.mainView}]];
Run Code Online (Sandbox Code Playgroud)

它崩溃了:

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'
Run Code Online (Sandbox Code Playgroud)

奇怪的是,自动布局尝试调用superview布局指南,因为它应该只符合UILayoutSupport协议。

我还注意到topLayoutGuide&bottomLayoutGuide被声明为readonly:

@property(nonatomic, readonly, retain) id<UILayoutSupport> topLayoutGuide
@property(nonatomic, readonly, retain) id<UILayoutSupport> bottomLayoutGuide
Run Code Online (Sandbox Code Playgroud)