iOS16适配

1、横竖屏切换

[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];
}


复制代码

1.1、屏幕旋转通知在iOS16无法处触发

需要重写UIViewController的viewWillTransitionToSize:withTransitionCoordinator:,在此函数里面处理UI。

1.2、iOS16 使用过YYTextView之后无法旋转屏幕

使用过UITextView之后,再调用函数 requestGeometryUpdateWithPreferences:geometryPreferences errorHandler: 请求无效,无法旋转屏幕

分析: 打印所有的connectedScenes

使用YYTextView之前

使用YYTextView之后

问题是当前的UIWindowScene里面多了一层YYTextView添加的YYTextEffectWindow,去掉这一层window就可以了。

2、xcode14 UIViewController在dealloc时发生崩溃

iOS16调试的时候报错

Application circumvented objective-c runtime dealloc initiation for <%s> object并崩溃

原因是: IOS16 苹果不允许重写系统控件分类(Categroy)中重写 + (void)initialize方法

3、使用xcode14打出来的包,在iOS12.2以下的系统发生崩溃

使用otool工具查看二进制文件发现

二进制里面多了一个 /usr/lib/swift/libswiftCoreGraphics.dylib (compatibility version 1.0.0, current version 120.100.0)

解决方法:

Build Phases -> Link Binary With Librarires 里面添加libswiftCoreGraphics.tbd

Apple Recommended(苹果推荐的解决方法)

xcode14 解决方法:

Build Setting -> other link flags 添加 -Wl,-weak-lswiftCoreGraphics
复制代码

4、如果UINavigationItem的titleView有自动布局,UI布局展示错误

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 链接

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值