Giter Site home page Giter Site logo

oalayoutanchor's Issues

`layoutMarginsGuide` Support

First of all, thanks for this library! It's worked out great so far.

Now, on to the issue: To gain 100% NSLayoutAnchor support, we need access to the new layoutMarginsGuide property on UIView, which allows using NSLayoutAnchor with relative margins. This would also require adding all of the UIView guides to UILayoutAnchor for full support.

For now our workaround has been getting the layoutMargins property and calling the constraintEqualToAnchor(constant:) method with he appropriate constant for the constraint. It would be great if the library handled this to be fully compatible with NSLayoutAnchor.

Thanks!

Nil layoutAnchor

_myLabel = [[UILabel alloc] init];
_myLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_titleLabel];

// This ends up being nil because _myLabel is an object, but it's leadingAnchor property is nil.
[_myLabel.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor constant:xPadding],

Both _myLabel and self.contentView are not nil.

My code keeps crashing (being put into an array) because the NSLayoutConstraint that is generated from the constraintEqualToAnchor method is nil.

Any ideas?

Can't compile on Xcode 7 beta

A new feature in Xcode 7 / Swift 2 / iOS 9 is that it compile-time checks whether you can call certain API's, including the UILayoutAnchor stuff.

So when I try to use OALayoutAnchor, which conforms to exactly the same API as the UILayoutAnchor, it (incorrectly) complains about topAnchor only being available from iOS 9...

only available on iOS 9.0 or newer

Constraints not matching up on iOS 8 and iOS 9.

The same code is rendering differently on iOS 8 and 9.

It appears when analyzing the constraints, there aren't any generated on the tableView (the class is a UIViewController with a UITableView added on it) in iOS 8.

This is how it looks on iOS 9 (renders correctly).

ios 9

This is how it looks on iOS 8 (renders incorrectly).

ios 8

Here's the code that's used for laying out the view controller.

CGFloat const padding = 10.0f;
CGFloat const buttonHeight = 52.0f;

self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.tableView.leadingAnchor constraintEqualToAnchor:self.tableView.superview.leadingAnchor constant:padding].active = YES;
[self.tableView.trailingAnchor constraintEqualToAnchor:self.tableView.superview.trailingAnchor constant:-padding].active = YES;
[self.tableView.topAnchor constraintEqualToAnchor:self.tableView.superview.topAnchor constant:3*padding].active = YES;
[self.tableView.bottomAnchor constraintEqualToAnchor:self.tableView.superview.bottomAnchor constant:-3*padding].active = YES;

_loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.view addSubview:_loginButton];

_loginButton.translatesAutoresizingMaskIntoConstraints = NO;
[_loginButton.leadingAnchor constraintEqualToAnchor:_loginButton.superview.leadingAnchor constant:padding].active = YES;
[_loginButton.trailingAnchor constraintEqualToAnchor:_loginButton.superview.trailingAnchor constant:-padding].active = YES;
[_loginButton.bottomAnchor constraintEqualToAnchor:_loginButton.superview.bottomAnchor constant:-padding].active = YES;
[_loginButton.heightAnchor constraintEqualToConstant:buttonHeight].active = YES;

_signupButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.view addSubview:_signupButton];
_signupButton.translatesAutoresizingMaskIntoConstraints = NO;
[_signupButton.leadingAnchor constraintEqualToAnchor:_loginButton.leadingAnchor].active = YES;
[_signupButton.trailingAnchor constraintEqualToAnchor:_loginButton.trailingAnchor].active = YES;
[_signupButton.bottomAnchor constraintEqualToAnchor:_loginButton.topAnchor constant:-padding].active = YES;
[_signupButton.heightAnchor constraintEqualToAnchor:_loginButton.heightAnchor].active = YES;

_onboardingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.view addSubview:_onboardingButton];
_onboardingButton.translatesAutoresizingMaskIntoConstraints = NO;
[_onboardingButton.leadingAnchor constraintEqualToAnchor:_signupButton.leadingAnchor].active = YES;
[_onboardingButton.trailingAnchor constraintEqualToAnchor:_signupButton.trailingAnchor].active = YES;
[_onboardingButton.bottomAnchor constraintEqualToAnchor:_signupButton.topAnchor constant:-padding].active = YES;
[_onboardingButton.heightAnchor constraintEqualToAnchor:_signupButton.heightAnchor].active = YES;

And below are the constraints generated.

The constraints generated on iOS 9 look like this:

TableView: (
    "<NSAutoresizingMaskLayoutConstraint:0x7fd71b9b9620 h=--& v=--& UIView:0x7fd71b82a3e0.midX == + 177.5>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fd71b9b7ad0 h=--& v=--& H:[UIView:0x7fd71b82a3e0(355)]>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fd71b9b9a10 h=--& v=--& UIView:0x7fd71b82a3e0.midY == + 32>",
    "<NSAutoresizingMaskLayoutConstraint:0x7fd71b9b84b0 h=--& v=--& V:[UIView:0x7fd71b82a3e0(64)]>"
)
Login: (
    "<NSContentSizeLayoutConstraint:0x7fd71b9bd210 H:[UIButton:0x7fd7196a1d10'Login'(55)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd71b9bd9b0 V:[UIButton:0x7fd7196a1d10'Login'(31)] Hug:250 CompressionResistance:750>",
    "<NSLayoutConstraint:0x7fd7196a2aa0 V:[UIButton:0x7fd7196a1d10'Login'(52)]>"
)
Sign up: (
    "<NSContentSizeLayoutConstraint:0x7fd71b9be300 H:[UIButton:0x7fd7196a3410'Register'(81)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd71b9be3a0 V:[UIButton:0x7fd7196a3410'Register'(31)] Hug:250 CompressionResistance:750>"
)
Onboarding: (
    "<NSContentSizeLayoutConstraint:0x7fd71b9be000 H:[UIButton:0x7fd7196a4da0'Picks? What's that...'(222)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd71b9bea40 V:[UIButton:0x7fd7196a4da0'Picks? What's that...'(46)] Hug:250 CompressionResistance:750>"
)

The constraints generated on iOS 8 look like this:

TableView: (
)
Login: (
    "<NSContentSizeLayoutConstraint:0x7fd5836e1900 H:[UIButton:0x7fd585921fe0'Login'(55)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd5836e1960 V:[UIButton:0x7fd585921fe0'Login'(31)] Hug:250 CompressionResistance:750>"
)
Sign up: (
    "<NSContentSizeLayoutConstraint:0x7fd5836a8900 H:[UIButton:0x7fd583794e90'Register'(81)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd5836a8960 V:[UIButton:0x7fd583794e90'Register'(31)] Hug:250 CompressionResistance:750>"
)
Onboarding: (
    "<NSContentSizeLayoutConstraint:0x7fd5858109f0 H:[UIButton:0x7fd5837967c0'Picks? What's that...'(222)] Hug:250 CompressionResistance:750>",
    "<NSContentSizeLayoutConstraint:0x7fd585810a50 V:[UIButton:0x7fd5837967c0'Picks? What's that...'(46)] Hug:250 CompressionResistance:750>"
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.