[UIDevice currentDevice] 使用setValue:forKey:的方式在iOS16上面已经不可用,继而要使用UIWindowScene里面的函数请求
- if (@available(iOS 16.0, *)) {
- UIWindowScene *windowScene = (UIWindowScene *)[[[UIApplication sharedApplication] connectedScenes] allObjects].firstObject;
- UIWindowSceneGeometryPreferencesIOS *perference = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
- perference.interfaceOrientations = 1 << deviceOrientation;
- [windowScene requestGeometryUpdateWithPreferences:perference errorHandler:^(NSError * _Nonnull error) {
- NSLog(@"error--%@", error);
- }];
- } else {
- [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:deviceOrientation] forKey:@"orientation"];
- [UIViewController attemptRotationToDeviceOrientation];
- }
-
-
- 复制代码
需要重写UIViewController的viewWillTransitionToSize:withTransitionCoordinator:,在此函数里面处理UI。
使用过UITextView之后,再调用函数 requestGeometryUpdateWithPreferences:geometryPreferences errorHandler: 请求无效,无法旋转屏幕
分析: 打印所有的connectedScenes
使用YYTextView之前
使用YYTextView之后
问题是当前的UIWindowScene里面多了一层YYTextView添加的YYTextEffectWindow,去掉这一层window就可以了。
iOS16调试的时候报错
Application circumvented objective-c runtime dealloc initiation for <%s> object并崩溃
原因是: IOS16 苹果不允许重写系统控件分类(Categroy)中重写 + (void)initialize方法
使用otool工具查看二进制文件发现
二进制里面多了一个 /usr/lib/swift/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 120.100.0)
解决方法:
Build Phases -> Link Binary With Librarires 里面添加libswiftCoreGraphics.tbd
xcode14 解决方法:
- Build Setting -> other link flags 添加 -Wl,-weak-lswiftCoreGraphics
- 复制代码
- extension UINavigationItem {
- func addView(_ view: UIView, _ color: UIColor = .clear) {
- if #available(iOS 13, *) {
- let tempTitleV = UIView()
- tempTitleV.backgroundColor = color
- tempTitleV.frame = CGRect(x: 0, y: 0, width: App.screenWidth - 100, height: App.navigationBarHeight)
- self.titleView = tempTitleV
- tempTitleV.addSubview(view)
- view.snp.makeConstraints { make in
- make.center.equalToSuperview()
- make.height.equalTo(App.navigationBarHeight)
- make.width.equalTo(App.screenWidth - 100)
- }
- } else {
- self.titleView = view
- }
- }
- }
相关链接:Apple Forums 链接