4
votes

I'm trying to get my application to rotate the interface when the device itself is rotated, but I can't get it right. I have added the supported interfaces in the plist info file and returned yes for the shouldRotateToInterfaceOrientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
        return YES;  
    } else {  
        return NO;  
    }  
} 

Is this how rotation is implemented?
Please help!

4
if you set a BP on these methods, does it get hit when you rotate the device?psychotik
I'm not sure what a BP is, sorry, I'm new to the iOS Programming environment.Olsi
I set the break point only on the first view to test it, and it get's hit four times when it launches the first time, and never when I rotate the simulator.Olsi
If the breakpoints aren't getting hit, then chances are that your UIViewController isn't actually set up as view controller for the window. The second bullet point of this article discusses the situation: developer.apple.com/library/ios/#qa/qa1688/_index.htmlThomasW

4 Answers

1
votes

Maybe try editing the info.plist and also add your supported orientations there?

Select your project --> Select your target --> Info --> Supported interface orientations and click on the plus sign 4 times to support these orientations:

Item 0   Landscape (left home button)
Item 1   Landscape (right home button)
Item 2   Portrait (top home button)
Item 3   Portrait (bottom home button)

Hope it helps!

0
votes

Make sure you've added shouldRotateToInterfaceOrientation to the view controllers that you want to support different orientations. It doesn't go in the app delegate.

0
votes

Supporting orientation is straight-forward if you're using standard UI elements so, assuming that's the case, you're on the right track.

If you're using a UITabController, all the views must support the same orientations, otherwise it defaults to the minimum (e.g. Portrait), I believe.

Also, if you're using NIBs for your views, make sure you have 'Autoresize subviews' checked when configuring the view in Interface Builder.

0
votes

if you are using UITabBarController, then you'll need to call it's subviews' shouldAutoratateToInterfaceOrientation.

suppose you have two tabs, please try to add the following two lines to method shouldAutorotateToInterfaceOrientation in the class that uses the UITabViewController.

[[tabBarController.viewControllers objectAtIndex:0] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
[[tabBarController.viewControllers objectAtIndex:1] shouldAutorotateToInterfaceOrientation:interfaceOrientation];

of course the "tabBarController" must be linked to the UITabBarController in your XIB file via IB.

Thanks,