Reputation: 16829
I'm trying this :
- (void)viewDidLoad {
[super viewDidLoad];
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
NSLog(@"PORTRAIT");
} else {
NSLog(@"LANDSCAPE");
}
}
but it seems that [[UIDevice currentDevice] orientation]
returns 0 so I can't know in which orientation the device is at that moment. How can I know it ?
Upvotes: 0
Views: 99
Reputation: 3603
I am using
UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation]
This from:
iOS Developer Library: Responding to Orientation Changes in a Visible View Controller
The window adjusts the bounds of the view controller’s view. This causes the view to layout its subviews, triggering the view controller’s viewWillLayoutSubviews method. When this method runs, you can query the app object’s statusBarOrientation property to determine the current user interface layout.
Upvotes: 1
Reputation: 676
You can check the orientation of device like this
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation))
{
NSLog (@"Device is in Portrait Mode");
}
else
{
NSLog (@"Device is in Landscape Mode");
}
Upvotes: 0