Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 890
user1214337 Avatar asked Dec 05 '22 18:12

user1214337


1 Answers

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

like image 145
NeverBe Avatar answered Dec 09 '22 14:12

NeverBe