One, the first time to do turn screen time to go a lot of detours, after a period of time do not write, found to forget almost, fortunately there are degrees Niang and Google, let me quickly find the feeling, below to talk about my understanding of the turn screen (there is no place or better way please leave a message, greatly appreciated!!!) )
IOS6 before the Turn screen is a simple way
-(BOOL) shouldautorotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation {
return (tointerfaceorientation = = uiinterfaceorientationportrait) | | (tointerfaceorientation = = Uiinterfaceorientationlandscapeleft) | | (tointerfaceorientation = = Uiinterfaceorientationlandscaperight);
}
IOS6 and later
① told Appdelegate to support the direction of the turn screen
-(Nsuinteger) application: (uiapplication *) application Supportedinterfaceorientationsforwindow: ( UIWindow *) window {
returnself. Orientation;
}
② in the need to turn the screen Viewcontroller
-(void) Viewwillappear: (BOOL) animated {
[Super viewwillappear:animated];
Appdelegate *del = (appdelegate *) [uiapplicationsharedapplication]. Delegate;
Del.Orientation = Uiinterfaceorientationmaskallbutupsidedown;
}
③ in the need to turn the screen Viewcontroller Plus
-(Nsuinteger) supportedinterfaceorientations {
Return uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscapeleft | Uiinterfaceorientationmasklandscaperight;
}
-(BOOL) shouldautorotate {
Returnyes;
}
Second, manual turn screen (press a button or an event trigger)
1. Fake Turn screen
① Turn status bar
[[UIApplication sharedapplication] Setstatusbarorientation:uiinterfaceorientationlandscapeleft Animated:YES];
② Rotate Current View
Self. View. Transform = cgaffinetransformrotate(self. View. Transform, m_pi /4);
2, use private method to turn the screen (this kind to be in arc), on AppStore cautious use
-(void) Setcustomorientation: (NSString *) orientate {
uiinterfaceorientation orientation = orientate. intvalue;
if ([[uidevice Currentdevice] respondstoselector:@selector (setorientation:)]) {
[[uidevice Currentdevice] performselector:@selector (setorientation:) Withobject: (ID) orientation];
}
}
iOS Automatic (manual) Turn screen