Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for UILayoutSupports (topLayoutGuide & bottomLayoutGuide) #27

Closed
raylillywhite opened this issue Nov 22, 2013 · 8 comments
Closed

Comments

@raylillywhite
Copy link

Support for building constraints with topLayoutGuide and bottomLayoutGuide would be great. From what I understand, using the length property of the guide to build the constraint would require us to also monitor for status bar frame changes, and reconfigure our constraints.

This looks like it would be difficult to support without a big refactor, but if you have ideas for how you'd like this implemented, I'd be happy to work on it.

@cloudkite
Copy link
Contributor

It was on the todo list, thanks for reminding me! I'll have a think and come back with some suggestions. In meantime I need to fix the tests as they no longer run due to the travis upgrade.

@cloudkite
Copy link
Contributor

So I started looking into this and surprisingly it already works without any changes!
As topLayoutGuide and bottomLayoutGuides are UIView subclasses. However I might make some changes to Masonry in order to support layout guide in a cleaner way.

If you look at the latest examples project it now has a example for using top and bottom layout guides

@raylillywhite
Copy link
Author

Oh, awesome. Nice find! Even with the casting, that's much cleaner than having to step outside masonry to create the constraint :)

In case someone finds this issue via search, here's the relevant part of the example:

[topView makeConstraints:^(MASConstraintMaker *make) {
    UIView *topLayoutGuide = (id)self.topLayoutGuide;
    make.top.equalTo(topLayoutGuide.bottom);
    make.left.equalTo(self.view);
    make.right.equalTo(self.view);
    make.height.equalTo(@40);
}];

Thanks @cloudkite! Feel free to close this issue. (I'm just leaving it open in case you wanted to track any additional changes you might make)

@huyz
Copy link

huyz commented May 30, 2014

That topLayoutGuide.bottom should be topLayoutGuide.mas_bottom, right? The example doesn't look updated.

@cloudkite
Copy link
Contributor

@huyz If you add #define MAS_SHORTHAND before importing Masonry.h then you can use the shorthand expressions ie view.bottom instead of view.mas_bottom

@lluisgerard
Copy link
Contributor

Just in case, if someone wants to do the same on Swift, just cast topLayoutGuide to AnyObject:

topView.makeConstraints({ (make: MASConstraintMaker!) -> Void in
    let topLayoutGuide : AnyObject = self.topLayoutGuide
    make.top.equalTo()(topLayoutGuide.mas_bottom)
...

@dlahyani
Copy link

With iOS9 they replaced the layout guides from _UILayoutGuide (internal class which is a subclass of UIView) to UILayoutGuide which is not a UIView anymore. Do you guys intend to support the new layout guides in the Masonry?

I opened an issue for that: Issue #207 .

@hjue
Copy link

hjue commented Aug 25, 2015

The length of topLayoutGuide is difference between viewDidLoad and viewWillAppear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants