To force a 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;}
How IOS forces you to go to a horizontal screen and toggle the screen through the device's status