tags:

views:

102

answers:

2

Hey,

I have the following code:

 -(void)viewWillAppear:(BOOL)animated {

    UIDeviceOrientation orientation = [[UIDevice currentDevice] UIInterface];

    if(orientation==UIDeviceOrientationLandscapeLeft || orientation==UIDeviceOrientationLandscapeRight) {
        NSLog(@"Device Landscape");
    } else {
        NSLog(@"Device Portrait");
    }
 }

This works perfectly for the simulator and on the device but ONLY if the iPad is not flat on a surface, for example if i lay the ipad on my desk and load the view it will say its FaceUp and so i cant detect the orientation when the view appears.

Any ideas of the best way to detect the interface orientation when the viewWillAppear is called??

Thanks

+5  A: 

You should use [self interfaceOrientation] instead of the device orientation.

Cory Kilger
A: 

First, do you know about the interfaceOrientation property of UIViewController? It looks like you are trying to duplicate it. If you really want to do that, simply subscribe to device orientation change notifications, check if the new orientation is valid interface orientation (the is a macro for that) and if yes, store the value to some variable (like lastSeenOrientation). Then you can rely on that value wherever you want.

zoul