Modal view. The power of the controller. Landscape Orientation in iOS 6

I have a UITabBarController presented in portrait mode. On one of the tabs, I have a button that shows the UIViewController modally (a simple segue storyboard does the action).

I want this modal view to display in landscape mode, but I can't get it to rotate automatically.

I have it in the modal view controller

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } 

I added LandscapeLeft to the supported .plist orientations (although this also allows the TabBar to rotate, which I don't want)

I also added this to the ViewDidLoad modal view.

 [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft; 

but I just can't make it spin by itself.

thanks

EDIT ----

AutoRotate doesn't seem to even get called!

Also, I'm trying to determine the orientation, and this code below always shows 2, regardless of orientation!

 if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) { NSLog(@"1"); self.hostView.frame = CGRectMake(0, 60, 200, 255); } else { NSLog(@"2"); self.hostView.frame = CGRectMake(0, 45, 480, 255); } 

EDIT 2 ---

My bad. I think I should have mentioned that I used iOS 6. The display automatically rotates to iOS 5. shouldAutorotateToInterfaceOrientation is deprecated, so I need to read the new methods.

+8
ios cocoa-touch xcode uiinterfaceorientation modalviewcontroller
source share
4 answers

IOS 6.0 Release Notes
"More responsibility goes to the application and the application delegate. Now iOS containers (like UINavigationController) will not consult their children to determine if they should autorotate."

-(BOOL)shouldAutorotate UIViewController in any container (e.g. UINavigationController) will not be called from IOS6.

Tried a solution using Category to add a method to an existing UINavigationController class.

inside the shouldAutorotate method, you can call the toAutorotate method in each view of the self.viewControllers controller. In fact, you can go to the controller of your child view.

+7
source share

If you want to force rotation in iOS6, your rootviewController must implement these methods:

 - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (BOOL)shouldAutorotate { return YES; } 
+6
source share

In iOS 6, it seems like this method can help set a specific orientation on iOS 6.

 - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } 

I'm still trying to get it to work and will be updated with any results.

+1
source share

I do exactly this in my application and do it through shouldAutoRotateToInterfaceOrientation, a little different than you:

 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) return (YES); return (NO); } 

for iOS 6, you should also set window.rootViewController = {your root view controller}; in your application. I hope this is your problem.

0
source share

All Articles