首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >被否决了,还有别的选择吗?

被否决了,还有别的选择吗?
EN

Stack Overflow用户
提问于 2019-07-05 09:41:10
回答 3查看 2.7K关注 0票数 6

我已经将我的应用程序目标更改为IOS 13,以检查我的应用程序中不推荐的方法,并且我正在收到以下警告:

不推荐'UIApplicationDidChangeStatusBarOrientationNotification‘:首先在iOS 13.0中不推荐使用viewWillTransitionToSize:withTransitionCoordinator:。 下面是我在我的项目中实现的代码。

代码语言:javascript
运行
复制
    - (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(onChangeStatusBarOrientationNotification:)
                                                     name:UIApplicationDidChangeStatusBarOrientationNotification
                                                   object:nil];
    }
    return self;
}

请给我推荐ios 12和ios 13的解决方案。

提前谢谢。

EN

Stack Overflow用户

发布于 2022-04-18 20:01:25

我也有同样的问题,下面是对我有用的东西:

在我的UIViewController中,我必须重写viewWillTransition函数并查看。

代码语言:javascript
运行
复制
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to:size, with: coordinator)
    let before = self.view.window?.windowScene?.interfaceOrientation
    coordinator.animate(alongsideTransition: nil) { _ in
        let after = self.view.window?.windowScene?.interfaceOrientation
        if before != after {
            // rotation detected, call you rotation handler here
        }
    }

}

来源:https://www.biteinteractive.com/dealing-with-ios-13-deprecations/

Mahmud Ahsan的回答很好,只是缺少了检测代码。

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56900491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档