开发者

How to get current orientation of device programmatically?

开发者 https://www.devze.com 2023-04-03 10:03 出处:网络
I want to know the device orientation, I used UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation

I want to know the device orientation, I used

 UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation

but this only works when I change the orientation otherwise it does not give anything (TRUE/FALSE).So how can I get current device orientation even when orientation is not changed.

Thanks in adv开发者_运维技巧ance!


To get orientation

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

and the possible orientations are

typedef enum {
  UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
  UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
  UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeLeft,
  UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeRight
} UIInterfaceOrientation;


UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

Gives an Implicit Enumeration Warning.

Use this instead:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];


Sorry if you've already done this, but have you looked into the beginGeneratingDeviceOrientationNotifications method, which enables notification generation for the device?

Also, are you looking for the device orientation or the interface orientation? If you're looking for a simpel Portrait vs Landscape orientation info, you should look into the interfaceOrientation of the view controller.

Hope this helps!

0

精彩评论

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