Abe_ 2013-11-20 03:46 采纳率: 0%
浏览 4008

ios7中shouldAutorotateToInterfaceOrientation被弃用?

// Applivations should use supportedInterfaceOrientations and/or shouldAutorotate..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0);

看不懂了。指导下iOS7上转屏幕在代码中的实现吧。

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-03-20 13:24
    关注

    该回答引用ChatGPT

    在 iOS 7 中,shouldAutorotateToInterfaceOrientation: 已经被弃用,现在应该使用 supportedInterfaceOrientations 和 shouldAutorotate 方法来实现屏幕旋转。


    首先,您需要在 Info.plist 文件中指定应用支持的方向。在 Xcode 中,选择您的项目 -> General -> Deployment Info -> Device Orientation 下,您可以选择支持的方向。例如,如果您想支持横向左右和竖向方向,则可以选择 Portrait、Landscape Left 和 Landscape Right。


    接下来,在您的视图控制器中,您需要实现 supportedInterfaceOrientations 和 shouldAutorotate 方法。例如,如果您的视图控制器支持所有方向,您可以这样实现:

    - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAll;
    }
    
    - (BOOL)shouldAutorotate {
        return YES;
    }
    

    supportedInterfaceOrientations 方法返回一个 UIInterfaceOrientationMask 值,表示视图控制器支持哪些方向。在这个例子中,我们返回 UIInterfaceOrientationMaskAll,表示支持所有方向。


    shouldAutorotate 方法返回一个布尔值,表示视图控制器是否应该自动旋转。在这个例子中,我们返回 YES,表示视图控制器可以自动旋转。


    如果您想限制视图控制器只支持某些方向,您可以在 supportedInterfaceOrientations 方法中返回相应的 UIInterfaceOrientationMask 值。例如,如果您只想支持横向方向,则可以这样实现:

    - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskLandscape;
    }
    
    - (BOOL)shouldAutorotate {
        return YES;
    }
    

    在这个例子中,supportedInterfaceOrientations 方法返回 UIInterfaceOrientationMaskLandscape,表示只支持横向方向。

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)