naresh
naresh

Reputation: 107

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 there any way to find out the simulator orientations.

Upvotes: 0

Views: 219

Answers (2)

JeremyT
JeremyT

Reputation: 70

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!");

Upvotes: 2

lxt
lxt

Reputation: 31304

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.

Upvotes: 2

Related Questions