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

Source: Internet
Author: User

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

In our projects, we often encounter vertical and horizontal screen switching, and a specific interface must be a specific display (flat screen or Portrait screen). This requires, for example, 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 inferring 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: Assume that the two methods below are implemented. The number of controllers that your application will walk through at the time of initialization is two methods below. Showldautorotate This method is again when you are about to rotate the screen, it will be called again, just to infer that there is a good yes or No.

When you need to, by Shouldautorot this variable open, do not need to close when it is possible. What is unclear, can increase the top of the QQ group. Ask me inside.

-(BOOL) Shouldautorotate    //whether rotation is supported. Assuming no, the lower method is not invoked, assuming yes, to call {    if (!shouldautorot) {        return NO;    } else{        return YES;}    } -(Nsuinteger) supportedinterfaceorientations{    return uiinterfaceorientationmaskallbutupsidedown;}

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.