`
shappy1978
  • 浏览: 702997 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Set Device Orientation

 
阅读更多

setOrientation in UIDevice is depreciate for iOS 5 and upper version. If we want to change or limit the orientation of current view controller. We still need to set the device orientation. In fact we still get 3 ways to handle it:

    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        SEL selector = NSSelectorFromString(@"setOrientation:");
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        [invocation setSelector:selector];
        [invocation setTarget:[UIDevice currentDevice]];
        int val = UIInterfaceOrientationLandscapeRight;
        [invocation setArgument:&val atIndex:2];
        [invocation invoke];
    }

 2nd:

objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeLeft);

 3rd:

    UIViewController *controller = [[UIViewController alloc] init];
    [self presentViewController:controller animated:NO completion:nil];
    [self dismissViewControllerAnimated:NO completion:nil];

 The first 2 method may have a risk to be rejected. I'm afraid Apple may think it a private API. The 3rd method, ok, I agree it's not a beautiful solution.

//************************************************************************************

DebugLog(@"%d,%d,%d,%d\n%d,%d,%d,%d",UIInterfaceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeRight,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationMaskPortrait,UIInterfaceOrientationMaskPortraitUpsideDown ,UIInterfaceOrientationMaskLandscapeRight, UIInterfaceOrientationMaskLandscapeLeft);

1,2,3,4

2,4,6,8

分享到:
评论

相关推荐

    Android权限表

    82. **SET_ORIENTATION**:应用可以更改设备的屏幕方向。 83. **SET_PREFERRED_APPLICATIONS**:应用可以设置默认应用。 84. **SET_PROCESS_FOREGROUND**:应用可以将自己置于前台,提高优先级。 85. **SET_TIME*...

    gc2145_parrotv1.1_r16m_验证完成_20170523_1408没有外层目录.7z

    R:\wyb\gc2145_parrotv1.1_r16m\lichee\linux-3.4\drivers\media\video\sunxi-vfe\device\gc2145.c 搜索:_regs[] static struct regval_list sensor_default_regs[] = { (默认分辨率是VGA分辨率:640x480) /* ...

    DeviceOrientationControlsVR:利用 DeviceOrientationControls.js,为three.js 中的VR 场景提供指南针方向

    5. **绑定事件监听器**:在窗口的`resize`和`deviceorientation`事件上添加监听器,以便适当地调整渲染和处理设备运动数据。 6. **更新控制器**:在每一帧的渲染循环中调用`DeviceOrientationControls.update()`,以...

    USB HID

    Orientation(方向):** 报告描述符中的项可能具有特定的方向性,这有助于区分输入项和输出项。 **10. Null Values(空值):** 某些情况下,报告描述符中可能会包含空值,这些值通常用于表示无效或未使用的数据...

    ImageMagick图片批量处理

    -synchronize synchronize image to storage device -taint declare the image as modified -texture filename name of texture to tile onto the image background -tile-offset geometry tile offset -...

    Android 权限(permission)整理

    31. `android.permission.SET_ORIENTATION`:允许程序改变屏幕方向,通常由系统自动处理。 32. 更多未列出的权限也有类似的功能,如改变系统状态、读取或写入特定系统数据等。 这些权限的使用应当谨慎,尤其是涉及...

    windows-server-2008R2WEB修改域用户密码图文介绍.docx

    横向的 css 样式 */}`、 `@media screen and (orientation: portrait){/* 横向的 css 样式 */}` 等媒体查询。 本文详细介绍了如何在 Windows Server 2008 R2 中使用 WEB 修改域用户密码,并简要介绍了基于 WebKit ...

    数位板压力测试

    The interface defines a standard orientation for reporting device native coordinates. When the user is viewing the device in its normal position, the coordinate origin will be at the lower left of the...

    android高手进阶教程

    android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#808080"> android:id="@+id/slidingdrawer" android:layout_width="fill_...

    ruoge_kerun_r8_ov2643显示为VGA_20160630_1613.7z

    only for facing back camera in android2.3, should be set in android4.0 used_zoom = 1 key_zoom_supported = true key_smooth_zoom_supported = false key_zoom_ratios = 100,120,150,200,230,250,300 key_max_...

    wen_ov5640_r16设置为vga分辨率20160720_1003.7z

    vip_define_sensor_list: If you want use sensor detect function, please set vip_define_sensor_list = 1, and ; verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_...

    vga_ov5640_ruoge_kerun_r8_20160629_1426.7z

    only for facing back camera in android2.3, should be set in android4.0 used_zoom = 1 key_zoom_supported = true key_smooth_zoom_supported = false key_zoom_ratios = 100,120,150,200,230,250,300 key_max_...

    ov7670_ruoge_kerun_r8增加摄像头的亮度20160630_1526.7z

    only for facing back camera in android2.3, should be set in android4.0 used_zoom = 1 key_zoom_supported = true key_smooth_zoom_supported = false key_zoom_ratios = 100,120,150,200,230,250,300 key_max_...

    索智R16开发板点亮ov7725+ov2640+ov5640_20160721_1726.7z

    vip_define_sensor_list: If you want use sensor detect function, please set vip_define_sensor_list = 1, and ; verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_...

    ov7725_r16_dev借用ov7736的驱动框架打开ov7725了20160719_1432.7z

    vip_define_sensor_list: If you want use sensor detect function, please set vip_define_sensor_list = 1, and ; verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_...

    !!!!gc2135_parrotv1.1_r16m_验证完成VGA分辨率_20171010_1513没有外层目录.7z

    vip_define_sensor_list: If you want use sensor detect function, please set vip_define_sensor_list = 1, and ; verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_...

    gc2135_parrotv1.1_r16m_验证完成VGA分辨率_20171010_1700没有外层目录.7z

    vip_define_sensor_list: If you want use sensor detect function, please set vip_define_sensor_list = 1, and ; verify that file /system/etc/hawkview/sensor_list_cfg.ini is properly configured! ; ;vip_...

Global site tag (gtag.js) - Google Analytics