"Beginning IOS 7 Development" proficient in iOS7 development "autorotation and autosizing

Source: Internet
Author: User

One, the relative position of rotation after the same

</span></strong ></p><p><strong><span style= "font-size:24px" ></span></strong></p><p><strong ><span style= "font-size:24px" ></span></strong></p><p><strong><span Style= "font-size:24px" ><span style= "font-size:24px" ><strong> II, after rotation </strong></span> Relative position change </span></strong></p><p><strong><span style= "font-size:24px" >     2.1 default: </span></strong></p><p><strong><span style= "font-size:24px" ></span></strong></p><p><strong><span style=" font-size:24px "></span></strong></p><p><strong><span style=" font-size:24px " ></span></strong></p><p><strong><span style= "font-size:24px" >     2.2 adjusted </span></strong></p><p><strong><span style= "font-size:24px" ></span></strOng></p><p><strong><span style= "font-size:24px" ></span></strong></p><p><strong><span style= "font-size:24px" >< /span></strong></p><p>&lT;strong><span style= "font-size:24px" > Three, Chick  </span></strong></p><p>< Strong><span style= "font-size:24px" >      3.1 which orientations are supported at the app level:</span></strong> </p><p><strong><span style= "font-size:24px" >   </span></strong></p> <p><strong><span style= "font-size:24px" ></span></strong></p><p>< Strong><span style= "font-size:24px" >     3.2 at Viewcontroller (xlib) level settings <strong>< Span style= "font-size:24px" > which directions are supported </span></strong></span></strong></p><p ><strong><span style= "font-size:24px" ></span></strong></p><p><strong ><span style= "font-size:24px "></span></strong></p><pre code_snippet_id=" 427694 "Snippet_file_name=" Blog_ 20140716_2_4821943 "name=" code "class=" OBJC ">////javiewcontroller.m//orientations////Created by Jason on 14-7-15. Copyright (c) 2014 Jason. All rights reserved.//#import "JAViewController.h" @interface Javiewcontroller () @[email protected] javiewcontroller-(void) viewdidload{[Super viewdidload];//do any additional setup after loading the view, typically from A nib.} -(void) didreceivememorywarning{[super didreceivememorywarning];//Dispose of any resources the can be recreated.} Override this method-(Nsuinteger) supportedinterfaceorientations{//return (uiinterfaceorientationmaskportrait| Uiinterfaceorientationmasklandscapeleft| Uiinterfaceorientationmaskportraitupsidedown);//return uiinterfaceorientationmaskall; Return (uiinterfaceorientationmasklandscaperight| Uiinterfaceorientationmasklandscapeleft| Uiinterfaceorientationmaskportraitupsidedown);} @end

3.3 Using constraint contstraints



3.4 When the above contraints method is not satisfied, shut it down, let the later in the VIEWCONTROLLER.M through the code implementation.



javiewcontroller.m//restructure////Created by Jason on 14-7-16.//Copyright (c) 2014 Jason. All rights reserved.//#import "JAViewController.h" @interface Javiewcontroller () @property (weak, nonatomic) Iboutlet UIButton *actionbutton1; @property (weak, nonatomic) Iboutlet UIButton *actionbutton2; @property (weak, nonatomic) Iboutlet UIButton *actionbutton3; @property (weak, nonatomic) Iboutlet UIButton *actionbutton4; @property (Weak, nonatomic) Iboutlet UIView *contentview; @end @implementation javiewcontroller-(void) viewdidload{[Super Viewdidload]    ;//starting from here uiapplication *app = [UIApplication sharedapplication];    Uiinterfaceorientation currentorientation = app.statusbarorientation; [Self dolayoutfororientation:currentorientation];//jumps to actual processing place}-(void) didreceivememorywarning{[super    Didreceivememorywarning]; Dispose of any resources the can be recreated.} Starting from here-(void) Willanimaterotationtointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation DuratIon: (Nstimeinterval) duration {[Self dolayoutfororientation:tointerfaceorientation]; }//determines the current direction-(void) Dolayoutfororientation: (uiinterfaceorientation) orientation{if (uiinterfaceorientationisportrait (orientation))    {[Self layoutportrait];    } else {[self layoutlandscape]; }}static const CGFloat buttonheight = 40;static Const CGFloat buttonwidth = 120;static Const cgfloat spacing = 20;//vertical Processing-    (void) layoutportrait {cgrect b = self.view.bounds;    CGFloat contentwidth = cgrectgetwidth (b)-(2 * spacing);    CGFloat contentheight = cgrectgetheight (b)-(4 * spacing)-(2 * buttonheight);     Self.contentView.frame = CGRectMake (spacing, spacing, contentwidth, contentheight);    CGFloat buttonrow1y = Contentheight + (2 * spacing);    CGFloat buttonrow2y = buttonrow1y + buttonheight + spacing;    CGFloat buttoncol1x = spacing;    CGFloat buttoncol2x = cgrectgetwidth (b)-buttonwidth-spacing; Self.actionButton1.frame = CGRectMake (buttoncol1x, buttonrow1y, Buttonwidth, buttonheight); Self.actionButton2.frame = CGRectMake (buttoncol2x, buttonrow1y, Buttonwidth, Butt    Onheight); Self.actionButton3.frame = CGRectMake (buttoncol1x, buttonrow2y, Buttonwidth, Butt    Onheight); Self.actionButton4.frame = CGRectMake (buttoncol2x, buttonrow2y, Buttonwidth, Butt Onheight);}    Transverse processing-(void) Layoutlandscape {cgrect b = self.view.bounds;    CGFloat contentwidth = cgrectgetwidth (b)-Buttonwidth-(3 * spacing);    CGFloat contentheight = cgrectgetheight (b)-(2 * spacing);     Self.contentView.frame = CGRectMake (spacing, spacing, contentwidth, contentheight);    CGFloat Buttonx = cgrectgetwidth (b)-buttonwidth-spacing;    CGFloat buttonrow1y = spacing; CGFloat buttonrow4y = cgrectgetheight (b)-Buttonheight-spacing; CGFloat buttonrow2y = buttonrow1y + Floor ((buttonrow4y-buttonrow1y) * 0.333    ); CGFloat buttonrow3y = buttonrow1y + Floor ((buttonrow4y-buttonrow1y) * 0.667    ); Self.actionButton1.frame = CGRectMake (Buttonx, buttonrow1y, Buttonwidth, Buttonhe    ight); Self.actionButton2.frame = CGRectMake (Buttonx, buttonrow2y, Buttonwidth, Buttonhe    ight); Self.actionButton3.frame = CGRectMake (Buttonx, buttonrow3y, Buttonwidth, Buttonhe    ight); Self.actionButton4.frame = CGRectMake (Buttonx, buttonrow4y, Buttonwidth, Buttonhe ight);} @end






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.