As I find it difficult sometimes to get what I expect from layouting with storyboards, I am playing around a bit with programmatic constraints... I am aware that getting started here will be more difficult – but hope the „end-game“ with this approach is more efficient. ;-)
When I use the following code on a simple viewController & mainView & centerView combo everything is as expected i.e. mainView fills entire screen available and centerView fills only the center part of mainView:
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(_centerView);
NSDictionary *metrics = @{@"padding":@15.0};
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-padding-[_centerView]-padding-|" options:0 metrics:metrics views:viewsDictionary]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-padding-[_centerView]-padding-|" options:0 metrics:metrics views:viewsDictionary]];
If I add the same viewController to an navigationController as root however (or define a different VC as root and push mine on later), it does not work as expected: the screen below the navBar is now just plain white.
I colored all views and the missing ones seem to „shine through“ a bit from the top left corner under the navigation bar. Why does the navigation controller „interfere“ with the above layout constraints at all? I was under the impression that the main view of the root view controller of a navigation controller by default fills the „remainder“ of the window below the navigation bar. Or am I mistaken and need to add constraints between navigation and my mainView? Or am I missing something else?
Any ideas?
BTW.: If someone knows a good tutorial or blog or other source that deals with the issue of programmatically composing screens & navigation between them (navigation controllers, tabbar controllers, views) and/or adding layout constraints I would be also very interested.
Thanks alot in advance.
OK, after some more testing, it appears that at least in my case I shouldn't set view.translatesAutoresizingMaskIntoConstraints = NO; for the rootView. As soon as I set it to YES (for this view only) it works again...