Xcode 升级11 适配 ⚠️记录~

2019-12-17  本文已影响0人  HH思無邪

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

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

2、 报错

3、 presentViewController适配

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

采用分类的形式,给 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的应用,直接删掉

  1. 要用到ipad的多线程的适配
@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()
        
    }
}
    // 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.
    }

上一篇下一篇

猜你喜欢

热点阅读