Masonry adding constraints to the order of attention

Source: Internet
Author: User

To add a constraint to a view, its dependent constraints must first exist, cannot rely on the code after the constraints, or cause unpredictable results, the following code can achieve the desired effect

- (void) makeconstraints {__weaktypeof(self) weakself =Self ; [Self.photomorebutton mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.right.equalTo (Weakself.photobutton). With.offset (-6);        Make.centerY.equalTo (Weakself.photobutton); Make.width.and.height.equalTo (@ -);        }]; [Self.photoimageview mas_makeconstraints:^ (Masconstraintmaker *Make )        {Make.centerY.equalTo (Weakself.photobutton);        Make.right.equalTo (WeakSelf.photoMoreButton.mas_left); Make.width.and.height.equalTo (@ -); }];}

But if you add the order of the constraints upside down, the following

- (void) makeconstraints {__weaktypeof(self) weakself =Self ; [Self.photoimageview mas_makeconstraints:^ (Masconstraintmaker *Make )        {Make.centerY.equalTo (Weakself.photobutton);        Make.right.equalTo (WeakSelf.photoMoreButton.mas_left); Make.width.and.height.equalTo (@ -);     }]; [Self.photomorebutton mas_makeconstraints:^ (Masconstraintmaker *Make ) {Make.right.equalTo (Weakself.photobutton). With.offset (-6);        Make.centerY.equalTo (Weakself.photobutton); Make.width.and.height.equalTo (@ -); }];}

The resulting effect is as

When you add a constraint, Photoimageview relies on Photomorebutton, which is not set at the time, so the result of the Photomorebutton is incorrect, so be careful when using masonry!

Masonry adding constraints to the order of attention

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.