开发者

iPhone - getting device orientation in first view controller's view will appear

开发者 https://www.devze.com 2023-04-10 08:38 出处:网络
I\'ve only one app delegate and view controller in my app. The app works in both portrait and landscape modes.

I've only one app delegate and view controller in my app. The app works in both portrait and landscape modes. In my view controller's viewWillAppear method I'm getting the orientation of the device usisng following code:

UIInterfaceOrientationIsPortrait([[开发者_StackOverflow社区UIDevice currentDevice] orientation])

First time when I am running the application, even when my device is in portrait, its giving the result as landscape. Why is it so. How can I solve this?


I have had a ton of problems with currentDevice.orientation Try this:

UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])


UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;


if (UIDeviceOrientationIsLandscape(deviceOrientation)
{
   //LandscapeView
}
else
{
   //PortraitView
}


From the documentation for UIDevice:

The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.

If you looked at the actual value being returned by 'orientation' you would see that it was 'UIDeviceOrientationUnknown'.

0

精彩评论

暂无评论...
验证码 换一张
取 消