Search code examples
iphoneiosuidevice

What is the best way to get the current orientation for setting views


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]


Solution

  • 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.