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