我已经将我的应用程序目标更改为IOS 13,以检查我的应用程序中不推荐的方法,并且我正在收到以下警告:
不推荐'UIApplicationDidChangeStatusBarOrientationNotification‘:首先在iOS 13.0中不推荐使用viewWillTransitionToSize:withTransitionCoordinator:。 下面是我在我的项目中实现的代码。
- (instancetype)init
{
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onChangeStatusBarOrientationNotification:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
}
return self;
}请给我推荐ios 12和ios 13的解决方案。
提前谢谢。
发布于 2022-04-18 20:01:25
我也有同样的问题,下面是对我有用的东西:
在我的UIViewController中,我必须重写viewWillTransition函数并查看。
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的回答很好,只是缺少了检测代码。
https://stackoverflow.com/questions/56900491
复制相似问题