How to get current orientation of device programmatically?
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!
精彩评论