Is there a way to force the interface orientation to change in iPhone?

Viewed 8962

I know how to allow/disallow the orientation to rotate using

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

However, I have the problem now where the phone might be in portrait (or upsidedown) and at some point I want to rotate the screen as if the user rotated to landscape. At this point, I don't want autorotate to work anymore. I want to force the interface orientation to stay in landscape. Is there a way to do this? I can probably figure out a hack for turning off the autorotate, but forcing the rotation in the first place I have no idea how to do.

Here's what I'm trying to do:

  • The app rotates to any and all orientations. Everything is normal.

  • An event occurs.

  • Now the autorotate only works for landscapeleft and landscaperight. Moreover, if the user is in portrait or portraitupsidedown, I programmatically rotate to landscaperight to lock the user into that orientation.

Just to make things trickier, I want to pop up a UIAlertView (I know how to do that) before the forced rotation, letting the user know what's going on, and I want to screen behind the alertView to rotate but not the alertView. Is this even possible?

Thanks.

5 Answers
Related