2

Possible Duplicate:
iPhone orientation

I want to check orientation(whether its landscape or portrait mode) of UIView.

How can I do this ?

Community
  • 1
  • 1
Devang
  • 11,258
  • 13
  • 62
  • 100
  • There's tons of posts on this as a simple search on "iPhone Check Orientation" will reveal. Please try to search first before posting. – Max MacLeod Sep 16 '11 at 09:44

3 Answers3

8

UIView Doesn't have orientation property.

You can check the current device orientation wherever you want using this:

    UIInterfaceOrientation  orientation = [UIDevice currentDevice].orientation;
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
        //portrait
    }
    else {
        //landscape
    }
Youssef
  • 3,582
  • 1
  • 21
  • 28
  • Its not UIInterfaceOrientation. its UIDeviceOrientation. And that will not check for landscape or portrait mode. :( – Devang Sep 16 '11 at 09:48
0

UIView doesn't have orientation property. You can check UIDevice or UIApplicationStatusBar orientation

beryllium
  • 29,669
  • 15
  • 106
  • 125
0

Implement the UIAccelerometerDelegate (I'm assuming that you have subClassed UIView) in your class as @interface YourView : UIView<UIAccelerometerDelegate> and then in the -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration method, check what is the value of acceleration.x. If it is close to 1 or -1 then the device is held up in landscape left/right. Make the same check on acceleration.y to determine portrait orientation

tipycalFlow
  • 7,594
  • 4
  • 34
  • 45