OGeek|极客世界-中国程序员成长平台

标题: ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:11
标题: ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向

在 ios10 中,不推荐使用 setStatusBarOrientation。旧项目代码的某些片段无法正常工作。那么如何解决它们呢?以下代码将根据需要更改 View Controller :

 float angle;
 CGRect rect;
//    UIInterfaceOrientation orientation;
    float fWidth = _viewController.view.bounds.size.width;
    float fHeight = _viewController.view.bounds.size.height;
    float fMaxValue = (fWidth > fHeight) ? fWidth : fHeight;
    float fMinValue = (fWidth > fHeight) ? fHeight : fWidth;

    if ((eScreenOrientation)ore == eScreenOrientation:andscape) {
        if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) {
//            orientation = UIInterfaceOrientationLandscapeRight;
            angle = M_PI_2;
        } else {
//            orientation = UIInterfaceOrientationLandscapeLeft;
            angle = -M_PI_2;
        }
        rect = CGRectMake(0, 0, fMaxValue, fMinValue);
    } else {
//        orientation = UIInterfaceOrientationPortrait;
        angle = 0;
        rect = CGRectMake(0, 0, fMinValue, fMaxValue);
    }

//  [[UIApplication sharedApplication] setStatusBarOrientation: orientation];
    _viewController.view.transform = CGAffineTransformMakeRotation(angle);
    _viewController.view.bounds = rect;
    [_viewController resetViewSize];



Best Answer-推荐答案


相信 -[UIApplication statusBarOrientation] 已被弃用以支持使用 UITraitCollection 和大小类。

同样来自苹果文档

@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientation __TVOS_PROHIBITED;

//状态栏方向的显式设置在 iOS 6.0 及更高版本中受到更多限制。 @property(readwrite, nonatomic) UIInterfaceOrientation statusBarOrientation NS_DEPRECATED_IOS(2_0, 9_0, "在 iOS 6.0 及更高版本中,状态栏方向的显式设置受到更多限制") __TVOS_PROHIBITED;

看来您不能将上述代码用于相同目的。

也许这个链接可以帮助你 Link to orientation

关于ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45099819/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4