Ios automatic (manual) screen conversion, ios

Source: Internet
Author: User

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];

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.