How to find out the simulator orientations?
iam developing one app .In that i want to find out the iphone orientations.I written the code for that one.Is 开发者_JAVA百科there any way to find out the simulator orientations.
Jeremy's answer is missing an exceedingly important piece of information about [[UIDevice currentDevice] orientation]
- as per the Apple documents:
The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications.
Before you call [[UIDevice currentDevice] orientation]
you must first call [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]
.
When you're done, you should also call endGeneratingDeviceOrientationNotifications
at some point.
However, it is worth noting that the simulator can at times fail to pass orientation changes through: I would strongly recommend testing your orientation changes on a device. There are edge cases you won't see on the simulator that will definitely occur on actual hardware.
This little snippet should work both in the simulator and on a physical device. You also need a few other bits of code for it it work as lxt pointed out.
[UIDevice currentDevice].orientation
Example:
if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait)
NSLog("The device orientation is portrait!");
else
NSLog("The device orientation is NOT portrait!");
精彩评论