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