views:

1763

answers:

2

This is just an example of the basic problem I'm having, so don't worry if this situation sounds a bit pointless ;)

Let's say I have an app that's mainly a UINavigationController just two levels deep. The top level is a table with a list of image filenames, and the second level has just a UIImageView showing the image for the filename you tapped.

For an app such as this, does anyone know a good way to allow the table at the top level to autorotate while keeping the second level of images fixed in portrait mode?

So far I've been able to almost get there... but when I tap a filename while in landscape mode, the image slides into view in the wrong orientation even if the second level view controller's shouldAutorotateToInterfaceOrientation returns yes for only portrait modes.

A: 

The problem is that if you use auto rotation the entire UI (including the UIWindow instance I believe) is rotated.

Anything pushed onto the navigation controller at this point will be done in landscape.

So when you push the imageview, that is exactly what you get.

To get this to work, you have to either:

  1. Handle the rotation of the root view manually (using a transform)
  2. Unrotate the image view by -PI/2 using a transform.

Either way you have to perform the transforms manually to get this to work.

As a side note, this may be bad UI design. As a user, I would expect as I drill down for images to appear rightside up. But this is without knowing the exact context of your app.

Corey Floyd
This is no longer true in iPhone OS 3.0. See my answer below.
Marco
+1  A: 

There was no good way to do this in iPhone OS 2.x, but in 3.0, they've dramatically improved it.

In 2.x, the shouldAutorotateToInterfaceOrientation: delegate method was only obeyed for changes to the orientation, so you'd get the behavior you describe: if it was rotated in another view controller, it would stay rotated through pushes and pops even if the new view controller didn't support rotation to that orientation.

In 3.0, UINavigationController polls shouldAutorotateToInterfaceOrientation: on each push or pop and obeys what it returns the way you'd expect, e.g.: if you're currently rotated in Landscape Left orientation, and you push an instance of a view controller that only supports Portrait orientation via shouldAutorotateToInterfaceOrientation:, it automatically and instantly flips the logical orientation and slides in the new view the correct way in Portrait orientation.

Note that this will only work on applications linked against (and therefore requiring) 3.0. For applications linked against 2.x, it will emulate the old behavior.

Marco
That sounds like exactly the behavior I was looking for. I'll have to try this again now that I have the new SDK. Thanks!
Cruinh