如何检查UIView的方向?

Dev*_*ang 2 iphone cocoa-touch objective-c ios4

可能重复:
iPhone方向

我想检查UIView的方向(无论是横向还是纵向模式).

我怎样才能做到这一点 ?

You*_*sef 8

UIView 没有方向属性.

您可以使用以下方法检查当前设备方向:

    UIInterfaceOrientation  orientation = [UIDevice currentDevice].orientation;
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
        //portrait
    }
    else {
        //landscape
    }
Run Code Online (Sandbox Code Playgroud)