关于ios设备的旋转判断问题

来源:互联网 发布:战地硬仗枪械数据 编辑:程序博客网 时间:2024/06/10 00:26

UIDeviceOrientation 是ios设备当前旋转方向   ,这个参数可以取值不能设置;

UIInterfaceOrientation   是程序界面当前旋转方向  这个你可以设置;

Portrait 表示 纵向 (屏幕直立),Landscape 表示 横向(屏幕横躺)

下面举个例子 说明:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    //声明一个指标,并取得当前设备的状况

    UIDevice *device = [UIDevicecurrentDevice] ;


    //取得当前Device的方向,来判断描述。(Device的方向形态为Integer

    switch (device.orientation) {

        caseUIDeviceOrientationFaceUp:

            NSLog(@"设备屏幕朝上平躺");

            break;

            

        caseUIDeviceOrientationFaceDown:

            NSLog(@"设备屏幕朝下平躺");

            break;

            

            //当系统无法获取 设备状态,可能是 斜躺

        caseUIDeviceOrientationUnknown:

            NSLog(@"未知方向");

            break;

            

        caseUIDeviceOrientationLandscapeLeft:

            NSLog(@"屏幕向左橫置");

            break;

            

        caseUIDeviceOrientationLandscapeRight:

            NSLog(@"设备屏幕朝左横置");

            break;

            

        caseUIDeviceOrientationPortrait:

            NSLog(@"设备屏幕直立");

            break;

            

        caseUIDeviceOrientationPortraitUpsideDown:

            NSLog(@"设备屏幕直立,上下颠倒");

            break;

            

        default:

            NSLog(@"设备方向无法辨识");

            break;

    }

    

    // Return YES for supported orientations

    return (interfaceOrientation ==UIInterfaceOrientationLandscapeLeft);//只支持向左横向, YES表示支持所有方向

}


1 0
原创粉丝点击