简体   繁体   中英

Forcing LandScape orientation without using [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationAnyOrientation]

I have a weird problem I can't figure out how to solve it! My app supports any type of orientation (portrait, landscape ect..), but a new section (view) I designed, is useful only in landscape. So I have to force my new view to be loaded in landscape once I pressed a button or rotate the device orientation when this particular view is created.

Using solve everything but I read on the web that using this API will lead your app to be rejected by Apple. Is it still true or I can use it?

Having lots of views I used a UIViewController as "container", so I can handle them better. I wounder if using this may be a problem itself... I tried to rotate the view with a CGTransform and "lock" the rotation using a BOOL inside the view container, this solved the layout problem so the view is displayed correctly but when a textView becomes firsresponder the keyboard is showed in portrait mode. That's why the device orientation is still portrait.

I also tried to work on the keyboard layout to display it correctly but nothing worked.

Thank you for any help you'll provide me!

Put this code in viewWillAppear

UIViewController *viewController = [[UIViewController alloc] init];
[viewController setModalPresentationStyle:UIModalPresentationCurrentContext];
viewController.view.frame = CGRectZero;
[self presentModalViewController:viewController animated:NO];
[self dismissModalViewControllerAnimated:NO];
[viewController release];

This will rotate new view controller to device orientation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM