Support UIViewController top and bottom layout guide
Closed this issue · 5 comments
Am I the only one who completely missed these two properties of UIViewController
?
@property id<UILayoutSupport> topLayoutGuide;
@property id<UILayoutSupport> bottomLayoutGuide;
These can be used when creating UILayoutConstraint
(since the constructor takes id
arguments) and they allows you to align views with translucent navigation bars, tab bars, toolbars and so on.
It would be great, if these could be used with KeepLayout, but I'm not sure how?
Is your how related to syntax? Then maybe:
view.keepTopOffsetTo(viewController.topLayoutGuide).equal = ...;
If it is in code, I don't know.
@duemunk Syntax is not such problem, but in whole project I assumed only UIView
objects can be layouted. Since these two guides don't even have public class I would need to use id
everywhere and that would reduce type-safety.
I have one idea about layout view. Each UIViewController
would have .layoutView
property, that would be automatically created as a subview of .view
and layouted using four constraints: left and right insets of zero & top and bottom aligned with these guides. So the size of this .layoutView
would be only the visible size of the .view
. The difference is described in code:
// This button is hidden under navigation bar:
self.button.keepTopAlignTo(self.view).equal = KeepRequired(0);
// This button is just under the navigation bar and fully visible:
self.button.keepTopAlignTo(self.layoutView).equal = KeepRequired(0);
Using a .layoutView
seems a bit more obtrusive than the rest of KeepLayout (messes with the view hierarchy). Nevertheless it seems like the only (at least best) way to go.
If it is clear in documentation that this is a hack that adds a "helper view" I guess it is ok. Remember .userInterenabled = NO;
and .backgroundColor = [UIColor clearColor];
on the .layoutView
.
I would make it off by default and lazy loaded, so the view wouldn't really be there unless you call .layoutView
getter.
Implemented in 798fce0. Includes an Example.