Forcing UIInterfaceOrientation changes on iPhone
Posted
by Andiih
on Stack Overflow
See other posts from Stack Overflow
or by Andiih
Published on 2010-04-22T09:29:15Z
Indexed on
2010/04/22
9:33 UTC
Read the original article
Hit count: 987
I'm strugging with getting an iPhone application which requires just about every push or pop in the Nav Controller Stack to change orientation.
Basically the first view is portrait, the second landscape the third portrait again (Yes I know this is less than ideal, but that's the design and I've got to implement it).
I've been through various advice on here....
http://stackoverflow.com/questions/995723/how-do-i-detect-a-rotation-on-the-iphone-without-the-device-autorotating
http://stackoverflow.com/questions/1824682/force-portrait-orientation-on-pushing-new-view-to-uinavigationviewcontroller
http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation
But without total success.
Setting to link against 3.1.2 my reading of the linked articles above seems to indicate that if my portrait view pushes a view with
Then then that view should appear rotated to landscape. What happens is it appears in its "broken" portrait form, then rotates correctly as the device is turned.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}
If I pop the controller back to my portrait view (which has an appropriate shouldAutoRotate...) then that remains in broken landscape view until the device is returned to portrait orientation.
I've also tried removing all the shouldautorotate messages, and instead forcing rotation by transforming the view. This kind of works, and I've figured out that by moving the status bar (which is actually hidden in my application) [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
the keyboard will appear with the correct orientation when desired.
The problem with this approach is that the status bar transform is weird and ugly when you don't have a status bar - a shadow looms over the page with each change.
So. What am I missing.
1) Am I wrong in thinking that in 3.1.2 (or possibly earlier) shouldAutorotateToInterfaceOrientation should provide the desired orientation simply by pushing controllers ?
2) Is there another way of getting keyboards to appear in the correct orientation.
3) Are the undocumented API calls the way to go (please no!)
© Stack Overflow or respective owner