IssamTP
IssamTP

Reputation: 2440

UIViewController interfaceOrientation problem

I have a Subclass of UIViewController as usual. When I load the App, I need to size some elements that I have to put in programmatically. Of course, the size depends on the interface orientation: So, I did:

- (void)viewDidLoad {
  switch( [self interfaceOrientation] ) {
     case UIInterfaceOrientationPortrait:
     case UIInterfaceOrientationPortraitUpsideDown:
          NSLog(@"Portrait");
          break:
     case UIInterfaceOrientationLandscapeLeft:
     case UIInterfaceOrientationLandscapeRight:
          NSLog(@"Landscape");
          break;
  }

But no matter of the orientation of the simulator/device, the case is always Portrait in viewDidLoad/WillAppear, even if everything rotate correctly. In the Plist I've added all supported orientations. Hints?

Upvotes: 1

Views: 4206

Answers (3)

anky_believeMe
anky_believeMe

Reputation: 484

I was working with the rotations and orientations of the iOS App. I found that self.interfaceOrientation will always give you a correct result if called in viewDidAppear or after that.

[UIApplication sharedApplication].statusBarOrientation should be preferred when adding a view directly to UIWindow.

Hope it helps.

Upvotes: 0

Devang Vyas
Devang Vyas

Reputation: 301

Try [UIApplication sharedApplication].statusBarOrientation and check for UIDeviceOrientationPortrait, UIDeviceOrientationPortraitUpsideDown etc in your switch as [self interfaceOrientation] is unreliable in my experience.

Upvotes: 8

tt.Kilew
tt.Kilew

Reputation: 6084

1) Make sure that interface orientation in willAppear returns incorrect interface orientation. 2) try to look here http://developer.apple.com/library/ios/#qa/qa1688/_index.html

3) Make sure that main view controller is only viewcontroller in window (there is only one vc in window)

Upvotes: 0

Related Questions