Stephane
Stephane

Reputation: 5078

Handling landscape display on iphone device rotation

I'm working on an iphone app with tab bars each one associated to a navigation controller. In one of these controllers I've a Table View showing some listing and when a row is selected another view displays specific informations and a button to see some related photos.

I'm having an issue displaying the photo view in landscape.

The photo view controller contains a UIImageView to display one photo at a time and this ImageView object size is 320x460 showing in full screen mode. To handle rotation I've added the following code:

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

But it's not rotating and iphone simulator status bar is still in the portrait position, so not rotated too.

I've also changed the method like this:

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

Still no changes on device rotation. And the options in Project->Summary(Tab)->Supported Device Orientation->Desired Orientations clearly enable landscape mode (right/left).

Can you help me understand what I may be missing ?

Thx for helping,

Stephane

Upvotes: 2

Views: 2383

Answers (3)

Gabriel
Gabriel

Reputation: 3045

Your looking in the wrong place: in your RootViewController.m file look for the following code:

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
//lots of useless comments
//
return (UIInterfaceOrientationIsPortrait(interfaceOrientation) ); //THIS LINE HERE
// return (UIInterfaceOrientationIsLandScape(interfaceOrientation) ); 

the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. You can change this to whatever to allow you to be able to rotate completely, keep it at a certain orientation, or whatever you desire...

Upvotes: -1

morningstar
morningstar

Reputation: 9122

With a tab bar controller, it will only rotate if your view controllers for all your tabs allow the orientation. Kind of annoying, but there it is. You need to override shouldAutorotateToInterfaceOrientation in all your other view controllers too, and they need to be able to smoothly adjust to those orientations.

If it's not practical to support landscape orientations on the other view controllers, maybe you could try some hacking, for example by subclassing UITabBarController and overriding its shouldAutorotateToInterfaceOrientation to instead return YES if the current view controller returns YES. But that might get your app rejected as not conforming to Human Interface Guidelines, since you are trying to circumvent standard interface behavior.

Upvotes: 2

Mayjak
Mayjak

Reputation: 1497

Check if you're not in some sort of a subclassed container view controller (like your own UINavigationController or UITabBarController subclasses). If that's the case make sure it does not override shouldAutorotateToInterfaceOrientation: method.

Upvotes: 0

Related Questions