iOS Delete AutoLayout

Source: Internet
Author: User

Sometimes, we need to dynamically change a value in the AutoLayout in view, such as moving the X-value, or the Y-value, what to do?

The following encapsulates a better way to remove: excerpt from Https://github.com/MakeZL/ZLAutoLayout (the framework that encapsulates AutoLayout)


The following is used to Zllayoutconstraint is an alias Nslayoutconstraint

typedef Nslayoutconstraint Zllayoutconstraint;

---------------

Remove all constraints

<span style= "FONT-SIZE:14PX;" > #pragma mark-remove view to Superview autolayout-(void) removeallautolayout{    [self removeconstraints: Self.constraints];    For (Zllayoutconstraint *constraint in self.superview.constraints) {        if ([Constraint.firstitem isequal:self]) {            [Self.superview removeconstraint:constraint];}}    </span>

---------------

Delete a single constraint

<span style= "FONT-SIZE:14PX;" > #pragma mark-remove single constraint-(void) Removeautolayout: (Zllayoutconstraint *) constraint{for    ( Zllayoutconstraint *constraint in self.superview.constraints) {        if ([constraint Isequal:constraint]) {            [ Self.superview removeconstraint:constraint];}}    } </span>


---------------

Delete multiple constraints

<span style= "FONT-SIZE:14PX;" > #pragma mark-remove constraints-(void) Removeautolayoutconstraints: (Nsarray *) constraints{for    ( Zllayoutconstraint *constraint in constraints) {for        (Zllayoutconstraint *superviewconstraint in self.superview.constraints) {            if ([Superviewconstraint Isequal:constraint]) {                [Self.superview Removeconstraint:constraint];}}}    </span>



I wish you all a happy!



iOS Delete AutoLayout

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.