How to get Device Orientation in Cocos2D, iPhone in Objective C?

By | April 17, 2012

Hello all……
We may need to know that what is your current device orientation.
Using the below code you can do this.

if([[UIDevice currentDevice] orientation] == kCCDeviceOrientationPortrait) {
            NSLog(@"Device is now in Portrait Mode");
}
else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeLeft) {
            NSLog(@"Device is now in LandscapeLeft Mode ");
}
else if ([[UIDevice currentDevice] orientation] == kCCDeviceOrientationLandscapeRight) {
            NSLog(@"Device is now in LandscapeRight Mode");
}
else if([[UIDevice currentDevice]orientation] ==
  kCCDeviceOrientationPortraitUpsideDown) {
            NSLog(@"Device is now in PortraitUpsideDown Mode");
ss="Apple-style-span" style="font-weight: normal;">
}

Note: If you have to explicitly set the orientation of your phone to any of the above you can set this in the appDelegate.m file. You can put an “||” (OR) symbol in between to set more than one.

Please leave your valuable comments if this post was useful…..

Leave a Reply

Your email address will not be published. Required fields are marked *