I have a UIViewController that returns YES
in shouldAutorotateToInterfaceOrientation:
for UIDeviceOrientationPortrait
and NO
for everything else. With that view on the top of the stack, I use pushViewController:animated:
to push a new UIViewController
. The new controller returns YES
for anything in shouldAutorotateToInterfaceOrientation:
.
The first view refuses to rotate (as expected). Once the second view is pushed, the user can rotate the device and the UI will rotate (also as expected). If the second view is in landscape mode and the user presses the back button (which calls popViewControllerAnimated:
), the first view will appear rotated (unexpected!).
If the user rotates the device back to portrait orientation, the view will rotate and then be stuck in portrait mode as before. This works but it's ugly for the user until they rotate back. So I'm in search of a way to make this view stay in portrait mode.
The only workaround I have found so far is to use -[UIDevice setOrientation:]
, which throws a warning (orientation
is read-only) but works since it is actually defined. This is a huge hack and I'd like a real solution. In search of a real solution I attached GDB to the Photos application (MobileSlideshow.app) and discovered that it too uses -[UIDevice setOrientation:]
. Being an internal application though I guess they have different rules.
Is there a correct way to achieve the expected autorotation behavior?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…