AutoLayout and Animation

Source: Internet
Author: User

1, add a view in Rootview, and set constraints, left, right, top, all set with super margin is 20, height is 100.

2, write code control

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4@property (Weak, nonatomic) Iboutlet UIView *Animationview;5 6 @property (nonatomic, assign) BOOL isforwadanimation;7 @end8 9 @implementationViewcontrollerTen  One- (void) Viewdidload { A [Super Viewdidload]; -     //additional setup after loading the view, typically from a nib. -Self.isforwadanimation =NO; the } -  - //change the spacing between animationview constraints and top when you click View -- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event + { -     if(self.isforwadanimation) +     { A[Self ReplaceTopConstrainOnView:self.animationView contant: -]; at     } -     Else -     { -[Self ReplaceTopConstrainOnView:self.animationView contant: $]; -     } -     //Start Animation in [self animateconstraints]; -Self.isforwadanimation =!self.isforwadanimation; to } +  - //change the value of a constraint the- (void) Replacetopconstrainonview: (UIView *) View contant: (float) Contant * { $[Self.view.constraints enumerateobjectsusingblock:^ (Nslayoutconstraint *constraint, Nsuinteger idx, BOOL *stop) {Panax Notoginseng         if(Constraint.firstitem = = View && Constraint.firstattribute = =nslayoutattributetop) -         { theConstraint.constant =contant; +         } A     }]; the } +  - //animating with UIView's class method $- (void) animateconstraints $ { -[UIView animatewithduration:2.0animations:^{ - [Self.view layoutifneeded]; the     }]; -}

3, Summary

Gets FirstItem If the constraint is relative to the top
Get SecondItem If the constraint is relative to the bottom

AutoLayout and Animation

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.