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?
Try [UIApplication sharedApplication].statusBarOrientation
and check for UIDeviceOrientationPortrait
, UIDeviceOrientationPortraitUpsideDown
etc in your switch as [self interfaceOrientation]
is unreliable in my experience.
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)
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.
精彩评论