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

    评论

报告相同问题?