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,表示只支持横向方向。

    评论

报告相同问题?

悬赏问题

  • ¥20 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏