美文网首页
Xcode 升级11 适配 ⚠️记录~

Xcode 升级11 适配 ⚠️记录~

作者: HH思無邪 | 来源:发表于2019-12-17 23:35 被阅读0次

    1、关闭暗黑模式 ,如果没有适配暗黑模式,在暗黑模式下会很丑

    在Info.plist文件添加 
    User Interface Style     ->    Light
    
    关闭暗黑模式

    2、 报错

    3、 presentViewController适配

    • 原因是iOS 13 多了一个新的枚举类型 UIModalPresentationAutomatic,并且是modalPresentationStyle的默认值。
      UIModalPresentationAutomatic实际是表现是在 iOS 13的设备上被映射成UIModalPresentationPageSheet。
      但是需要注意一点PageSheet 与 FullScreen 生命周期并不相同 FullScreen会走完整的生命周期
      ,PageSheet因为父视图并没有完全消失,所以viewWillDisappear及viewWillAppear并不会走,
      如果这些方法里有一些处理,还是换个方式,或者用FullScreen

    一句话全局适配,摘自 简书猫爪

    采用分类的形式,给 UIViewController 增加一个分类,写入方法
    //Objective-C, 直接写在 .m 中
    @implementation UIViewController (iOS13)
    
    - (UIModalPresentationStyle)modalPresentationStyle{
        return UIModalPresentationFullScreen;
    }
    @end
    

    4、 私有API被封禁(KVC限制),禁止访问

    SearchBar

    if ([[[UIDevice currentDevice]systemVersion] floatValue] >=13.0) {
           searchField = _vSearchBar.searchTextField;
       }else{
          searchField = [self valueForKey:@"_searchField"];
       }
    

    修改TextFiled的占位符字体大小以及颜色

    [_textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
    [_textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    
    替换成
    _textField.attributedPlaceholder = [[NSAttributedString alloc] 
    initWithString:@"姓名" attributes:@{NSFontAttributeName:
    [UIFont systemFontOfSize:14]
    ,NSForegroundColorAttributeName:[UIColor redColor]}];
    

    5、UI调整

    1. UISegmentedControl 修改选择背景色
      iOS13中 ,UISegmentedControl默认样式变为白底黑字
        if (@available(iOS 13.0, *)) {
                _segmented.selectedSegmentTintColor = Stock_Red;
            } else {
                _segmented.tintColor = Stock_Red;
            }
    
    
    1. webview 全部要用WKWebview替换

    6、新增SceneDelegate 适配

    作用:据说为iPad的多进程准备的

    1.方案 不需要适配ipad的应用,直接删掉

    • 删除 SceneDelegate的文件
    • 删除AppDelegate中关于SceneDelegate的函数
    • 删除info.plist中的Application Scene Manifest选项
    • AppDelegate中添加window属性
    1. 要用到ipad的多线程的适配
    • 只有iOS 13 后才启用有SceneDelegate及相关函数,@available(iOS 13.0, *)

    • SceneDelegate 代码

    @available(iOS 13.0, *)
    class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
        var window: UIWindow?
    
       func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
      
            //需要用到多线程的时候      
            guard let windowScene = (scene as? UIWindowScene) else { return }
            
            let nav = YHNavigationController.init(rootViewController: HomeViewController())
                 nav.view.backgroundColor = UIColor.white
                 window = UIWindow.init(windowScene: windowScene)
                 window?.rootViewController = nav
                 window?.makeKeyAndVisible()
            
        }
    }
    
    • AppDelegate 代码
        // MARK: UISceneSession Lifecycle
        //使用 @available(iOS 13.0, *)进行判断,如果系统没到达13.0的话就不启用该段代码。
     @available(iOS 13.0, *)
        func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
            // Called when a new scene session is being created.
            // Use this method to select a configuration to create the new scene with.
            return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
        }
     @available(iOS 13.0, *)
        func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
            // Called when the user discards a scene session.
            // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
            // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
        }
    
    

    相关文章

      网友评论

          本文标题:Xcode 升级11 适配 ⚠️记录~

          本文链接:https://www.haomeiwen.com/subject/oqtynctx.html