Force UIInterfaceOrientation changes on iPhone

I am trying to get an iPhone app that requires almost every click or pop up on the Nav controller stack to change orientation.

Basically the first look is a portrait, the second is the third portrait again (yes, I know that this is less than ideal, but that the design and I have to implement it).

Here I got various tips ...
How to determine the rotation on the iPhone without autorotation of the device? Customize portrait orientation when clicking a new view on the UINavigationViewController
Is there a documented way to set iPhone orientation?
But without complete success.

The setup for linking to 3.1.2 my reading of the related articles above seems to indicate that if my portrait look pushes the view with

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) ); } 
Then this view should look turned towards the landscape. What happens is that it appears in its β€œbroken” portrait form, and then rotates correctly when the device is rotated.

If I return the controller back to my portrait (which has the corresponding mustAutoRotate ...), then it will remain in the broken landscape view until the device returns to portrait orientation.

I also tried deleting all ifautorotate messages and force rotation instead by changing the view. This kind of work, and I realized that by moving the status bar (which is actually hidden in my application) [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; , the keyboard will be displayed in the correct orientation if necessary.

The problem with this approach is that the status bar conversion is weird and ugly when you don't have a status bar - the shadow hangs over the page with every change.

So. What am I missing.

1) Am I not mistaken that in 3.1.2 (or perhaps earlier) the desired direction should be set simply by pressing the controllers?

2) Is there any other way to get the keyboard in the correct orientation.

3) Is the undocumented API a call (please, no!)

+8
objective-c iphone uiinterfaceorientation
Apr 22 '10 at 9:29
source share
1 answer

You should not use [UIViewController shouldAutorotateToInterfaceOrientation:] to initiate a change in orientation; it is only there to let the system know if automatic spins are allowed. You should still update it to indicate the orientation that is allowed.

If you want to change the orientation when a specific view is displayed, you must call [UIApplication setStatusBarOrientation:animated:] inside your override method [UIViewController viewWillAppear:] for each of the view controllers that cause the specific orientation. This will cause a change when the view is pushed onto the stack and when it is deleted. Make sure you call super on your override method.

It is also a suitable place to change the display of the status bar if this is something happening.

+4
Apr 22 '10 at 15:00
source share



All Articles