• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 不推荐使用 setStatusBarOrientation,如何在 ios10 中更改设备方向

[复制链接]
菜鸟教程小白 发表于 2022-12-13 02:11:52 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap