user1214337
user1214337

Reputation: 41

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!

Upvotes: 4

Views: 3539

Answers (1)

NeverBe
NeverBe

Reputation: 5038

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

Upvotes: 16

Related Questions