(9/18) Re-learning Standford_ios7 Development _ Animation, Automatic layout _ course Notes

Source: Internet
Author: User

Recently started an internship, not much time to update the =_=

Nineth Lesson:

1, the last lesson demo:dropit complete realization

Https://github.com/NSLogMeng/Stanford_iOS7_Study/commit/cfc24c2c4300185d972cf151872d313414a48d32

2, AutoLayout

More simple, please refer to the courseware https://github.com/NSLogMeng/Stanford_iOS7_Study/blob/master/Slides/Lecture%209%20Slides.pdf

The implementation of the course is visualized in storyboard, this article introduces two methods:

①nslayoutconstraint

+(instancetype) Constraintwithitem: (ID) view1                                       attribute: (nslayoutattribute) attr1                                     Relatedby: ( nslayoutrelation)                             relation toitem: (ID) view2                                       attribute: (nslayoutattribute) attr2                                      multiplier: (cgfloat) Multiplier constant: (cgfloat) C; // constraint: Item1.attribute = (>=,<=related) multiplier * Item2.attribute + constant // add constraint with UIView -(void) AddConstraint: (Nslayoutconstraint *) constraint

②visual Format Language (VFL)

Official documentation is easy to understand

Grammar:

meaning syntax syntax
h: off Line < Span style= "color: #000000;" >>=,<=,==
vertical v: empty The Gap -
Views [View] Priority level @value
Superview |

Example:

    

Code implementation Examples:

- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.UIButton *button1 =[[UIButton alloc] init]; Button1.backgroundcolor=[self randomcolor]; [Button1 Settitle:@"button1"Forstate:uicontrolstatenormal]; Button1.translatesautoresizingmaskintoconstraints= NO;//manually created code that uses the VFL must change this propertyButton1.layer.cornerRadius =4.0f;        [Self.view Addsubview:button1]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"h:|-[button1]-|"Options0Metrics:nil Views:nsdictionaryofvariablebindings (button1)]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"v:|-20-[button1 (width)]"Options0metrics:@{@"width": @ -} views:nsdictionaryofvariablebindings (button1)]; UIButton*button2 =[[UIButton alloc] init]; Button2.backgroundcolor=[self randomcolor]; [Button2 Settitle:@"Button2"Forstate:uicontrolstatenormal]; Button2.translatesautoresizingmaskintoconstraints= NO;//manually created code that uses the VFL must change this propertyButton2.layer.cornerRadius =4.0f;        [Self.view Addsubview:button2]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"h:|-[button2]-|"Options0metrics:nil views:nsdictionaryofvariablebindings (button2)]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"V:[button1]-44-[button2 (+)]"Options0metrics:nil views:nsdictionaryofvariablebindings (button1,button2)]; Uitabbar*tabbar =[[Uitabbar alloc] init]; Tabbar.bartintcolor= [Uicolor colorwithred:102/255.0fGreen204/255.0fBlue255/255.0fAlpha1.0f]; Tabbar.translatesautoresizingmaskintoconstraints= NO;//manually created code that uses the VFL must change this propertyUitabbaritem*item1 =[[Uitabbaritem alloc] init]; [Item1 Settitle:@"item1"]; Uitabbaritem*ITEM2 =[[Uitabbaritem alloc] init]; [Item2 settitle:@"item2"]; Uitabbaritem*ITEM3 =[[Uitabbaritem alloc] init]; [Item3 Settitle:@"Item3"]; Tabbar.items=@[item1,item2,item3];    [Self.view Addsubview:tabbar]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"h:|[tabbar]|"Options0metrics:nil views:nsdictionaryofvariablebindings (TabBar)]; [Self.view addconstraints:[nslayoutconstraint Constraintswithvisualformat:@"V:[tabbar (]|)"Options0metrics:nil views:nsdictionaryofvariablebindings (TabBar)];    [Button1 addtarget:self Action: @selector (TouchButton1) Forcontrolevents:uicontroleventtouchdown]; }

Note: The ① code creates a view to add button1.translatesautoresizingmaskintoconstraints = NO;

②metrics stores the values (dictionaries) of the variables in the VFL, you can refer to the button1 constraints

The ③views parameter corresponds to the value of view in the VFL (by Nsdictionaryofvariablebindings (...). Achieve

3. Homework

Haven't done the =_=, the back complements.

Course Video Address: NetEase Open class: Http://open.163.com/movie/2014/1/B/P/M9H7S9F1H_M9H80K2BP.html

or itunes U search Standford Course

(9/18) Re-learning Standford_ios7 Development _ Animation, Automatic layout _ course Notes

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.