Ios automatic (manual) screen conversion, ios
I. The first time I made a screen conversion, I had a lot of detours. After a while I did not write, I found that I forgot about it. Fortunately, duniang and google made me quickly find a feeling, next, let's talk about my understanding of screen conversion (please leave a message if there is something wrong or a better method. Thank you very much !!!)
The screen conversion method before iOS6 is simple.
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) toInterfaceOrientation {
Return (toInterfaceOrientation = UIInterfaceOrientationPortrait) | (toInterfaceOrientation = UIInterfaceOrientationLandscapeLeft) | (toInterfaceOrientation = UIInterfaceOrientationLandscapeRight );
}
IOS6 and later
① Inform Appdelegate of the support for screen Conversion
-(NSUInteger) application :( UIApplication *) application supportedInterfaceOrientationsForWindow :( UIWindow *) window {
Returnself. orientation;
}
② In the viewController for screen Conversion
-(Void) viewWillAppear :( BOOL) animated {
[Super viewWillAppear: animated];
AppDelegate * del = (AppDelegate *) [UIApplicationsharedApplication]. delegate;
Del. orientation = UIInterfaceOrientationMaskAllButUpsideDown;
}
③ Add
-(NSUInteger) supportedInterfaceOrientations {
Return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
-(BOOL) shouldAutorotate {
ReturnYES;
}
2. Manual Screen conversion (triggered by pressing a button or an event)
1. Fake screen Rotation
① Turn to the status bar
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated: YES];
② Rotate the current view
Self. view. transform = CGAffineTransformRotate (self. view. transform, M_PI/4 );
2. Use a private method to screen (this type should be in ARC), and use Appstore with caution
-(Void) setCustomOrientation :( NSString *) orientate {
UIInterfaceOrientation orientation = orientate. intValue;
If ([[UIDevice currentDevice] respondsToSelector: @ selector (setOrientation :)]) {
[[UIDevice currentDevice] performSelector: @ selector (setOrientation :) withObject :( id) orientation];
}
}