Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad launch orientation when flat on surface

Tags:

ios

iphone

ipad

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 portrait 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

like image 201
Steve Avatar asked Oct 10 '10 17:10

Steve


1 Answers

[[UIApplication sharedApplication] statusBarOrientation] also works if you are somewhere in the code that does not have access to [self interfaceOrientation]

like image 118
Kevin Avatar answered Sep 20 '22 18:09

Kevin