I want to detect the current orientation for setting the view, which will be the better way for it from the below methods and how ?

[[UIDevice currentDevice]orientation]

[[UIApplication sharedApplication] statusBarOrientation]

有帮助吗?

解决方案

You can use [[UIApplication sharedApplication] statusBarOrientation] to detect device orientation.

This method returns orientation value for all cases but if you use

[[UIDevice currentDevice]orientation]

sometimes you get unknown orientation.

I hope that works for you.

其他提示

you can use below code:

if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
     NSLog(@"-Landscape");
}
 else 
{
     NSLog(@"-Portrait");
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top