Possible Duplicate:
iPhone orientation
I want to check orientation(whether its landscape or portrait mode) of UIView.
How can I do this ?
Possible Duplicate:
iPhone orientation
I want to check orientation(whether its landscape or portrait mode) of UIView.
How can I do this ?
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
}
UIView doesn't have orientation property. You can check UIDevice or UIApplicationStatusBar orientation
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