Should the topLayoutGuide and bottomLayoutGuide function be implemented in subclasses of the UIViewController?

I'm trying to create a container view controller that provides some overlay views, such as UINavigationController and UITabBarController, for view controllers in iOS 7. To correctly create a hidden view, I tried everything that I can think of relates to the -bottomLayoutGuide implementation as in a container, so in view controllers, but no luck. The method is called, but the value does not seem to be used.

I put together a quick example at https://github.com/stefanfisk/custom-layout-guides , but there I couldnโ€™t even access the accessories.

+7
autolayout uiviewcontroller ios7
source share
1 answer

I found that when you set restrictions in the code, for example

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][mainView]" options:0 metrics:nil views:@{@"topLayoutGuide" : self.topLayoutGuide, @"mainView" : self.mainView}]]; 

failure:

 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' 

It is strange that Auto Layout is trying to call superview in the layout guide, since it should only conform to the UILayoutSupport protocol.

I also noticed that topLayoutGuide and bottomLayoutGuide declared as readonly :

 @property(nonatomic, readonly, retain) id<UILayoutSupport> topLayoutGuide @property(nonatomic, readonly, retain) id<UILayoutSupport> bottomLayoutGuide 
+2
source share

All Articles