Little fat say things------iOS force to be turned into a horizontal screen way

Source: Internet
Author: User

has been encountering this problem, today finally found a solution.

In our project, we often encounter the vertical and horizontal screen switch, and a specific interface must be a specific display (flat screen or Portrait screen). This requires the following processing.

Force to horizontal screen: if ([[[Uidevice Currentdevice] Respondstoselector: @selector (setorientation:)]) {            SEL selector = Nsselectorfromstring (@ "setorientation:");            Nsinvocation *invocation = [Nsinvocation invocationwithmethodsignature:[uidevice instancemethodsignatureforselector : selector]];            [Invocation setselector:selector];            [Invocation Settarget:[uidevice Currentdevice];            int val = uiinterfaceorientationlandscaperight;            [Invocation setargument:&val atindex:2];            [Invocation invoke];}

method Two: Set the Transform property of the view by judging the status bar.

-(void) Deviceorientationdidchange: (nsnotification *) notification{uiinterfaceorientation interfaceOrientation = [[    UIApplication sharedapplication] statusbarorientation];    CGFloat startrotation = [[Self valueforkeypath:@ "layer.transform.rotation.z"] floatvalue];    Cgaffinetransform rotation; Switch (interfaceorientation) {Case uiinterfaceorientationlandscapeleft:rotation = Cgaffinetransformma            Kerotation (-startrotation + m_pi * 270.0/180.0);        Break Case uiinterfaceorientationlandscaperight:rotation = cgaffinetransformmakerotation (-startrotation + M_PI * 90.            0/180.0);        Break  Case uiinterfaceorientationportraitupsidedown:rotation = cgaffinetransformmakerotation (-startRotation + M_PI *            180.0/180.0);        Break            Default:rotation = cgaffinetransformmakerotation (-startrotation + 0.0);    Break } view.transform = rotation;}

Note: If you implement the following two methods, your application will be initialized at the time of the number of controllers to walk how many times the bottom two methods. Showldautorotate This method is again when you are about to rotate the screen, it will be called again, as long as the right here to judge yes or no is good. When you need to shouldautorot this variable to open, do not need to close when you can. What do not understand, you can join the top of the QQ group, inside asked me.
-(BOOL) Shouldautorotate    //Whether rotation is supported, if no, the method below will not be called, if yes, {if    (!shouldautorot) {        return NO;    } else{        return YES;}    } -(Nsuinteger) supportedinterfaceorientations{    return uiinterfaceorientationmaskallbutupsidedown;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Little fat say things------iOS force to be turned into a horizontal screen way

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.