美文网首页工作生活
iOS 13 更新内容与适配

iOS 13 更新内容与适配

作者: 爱喝农药de清凉 | 来源:发表于2019-07-02 15:22 被阅读0次
    331562055015_.pic.jpg
    iOS13测试版已经发布了,寡人尝试了一波更新,发现了一些问题,一下列出寡人遇到的问题与解决办法,可能不全,待补充

    自定义导航栏

     /* 自定义导航栏 */
        UINavigationBarAppearance * costomNavBar = [[UINavigationBarAppearance alloc] init]; 
    /* 导航需要的富文本设置 可写成2个,一个标准的,一个大字体的 */
     NSDictionary *attrDict = @{ NSFontAttributeName:[UIFont systemFontOfSize:10], NSForegroundColorAttributeName: [UIColor blueColor] };
        /* 标准字体的 富文本 */
        costomNavBar.titleTextAttributes = attrDict;
        /* 大标题 */
        costomNavBar.largeTitleTextAttributes = attrDict;
        /* 设置普通自定义导航条 */
        nav.navigationBar.standardAppearance = costomNavBar;
        /* 紧凑高度导航栏外观设置 */
        nav.navigationBar.compactAppearance = costomNavBar;
        /* 是否显示大标题 */
        nav.navigationBar.prefersLargeTitles = YES;
        /* 滚到头时 导航显示 */
        nav.navigationBar.scrollEdgeAppearance = costomNavBar;
    

    Search

    1.Search TextFiled

    - (void)setShowsScopeBar:(BOOL)show animated:(BOOL)animate;
     
    新属性: searchTextField
    注意:iOS 13 以后不能使用 KVC 方法获取 输入框的UITextField,会崩溃
    代码示例:      UITextField * searchField = [_searchBar valueForKey:@"_searchField"]; 
    应改为 _searchBar. searchTextField;
    新增代理:UISearchTextFieldDelegate
    //通过 searchToken(新增标识) 搜索
    - searchTextField:itemProviderForCopyingToken:
    

    2.Search Token

    image.png
    UISearchToken * token = [UISearchToken tokenWithIcon:[UIImage imageNamed:@"旺旺"] text:@"喵了个咪"];
    
    

    presentViewController

    兼容问题:

    1. presentViewController弹出的带导航的控制器如果采用 top,bottom 这种,会出现视图距离导航偏差问题,因为它不再从 (0,0)布局了
      建议宏定义 self.navigationController.navigationBar.maxY 从导航条下布局

    2.dismiss VC 后,不再走 View 生命周期方法

     - (void)viewWillAppear:(BOOL)animated;
    - (void)viewWillDisappear:(BOOL)animated;
    

    如果在该方法设置初始化事件,请注意该问题

    注意:如果不想要这种【小卡片】式弹出可以修改 .modalPresentationStyle
        UINavigationController * nav  = [[UINavigationController alloc] initWithRootViewController:testVC];
        testVC.modalPresentationStyle = UIModalPresentationFullScreen;
    /* 如果还是不行,请尝试修改导航的 modalPresentationStyle*/
        [self presentViewController:nav animated:YES completion:nil];
    
    

    另外,UIViewController 增加一个了属性 isModalInPresentation,默认为 false,当该属性为 false 时,用户下拉可以 dismiss 控制器,为 true 时,下拉不可以 dismiss控制器。该属性可以配合有编辑功能的控制器使用


    DeviceToken

    #include <arpa/inet.h>                //(友盟提供)
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        if (![deviceToken isKindOfClass:[NSData class]]) return;
        const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
        NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
                              ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
                              ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
                              ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
        NSLog(@"deviceToken:%@",hexToken);
    }
    

    Window

    初始化:
    在 SceneDelegate 的 willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions 方法中 初始化窗口

        UIWindowScene * windowScene = [[UIWindowScene alloc] initWithSession:session connectionOptions:connectionOptions];
        
       _window = [[UIWindow alloc] initWithWindowScene:windowScene];
    
    

    UIWindowScene 是管理应用程序的一个或多个窗口的特定类型的对象,有以下属性:

    windows , screen 窗口的一些东西

    
    //描述场景当前环境的特征,例如大小等级和比例因子
    @property(nonatomic, readonly) UITraitCollection *traitCollection;
    //方向,你懂得
    @property(nonatomic, readonly) UIInterfaceOrientation interfaceOrientation;
    //状态栏当前配置
    @property(nonatomic, readonly) UIStatusBarManager *statusBarManager;
    

    还要说下这个 可以去官网看下

    //用于管理场景中发生的特定于应用程序的任务的其他方法
    @protocol UIWindowSceneDelegate
    //用于响应场景中发生的生命周期事件的核心方法。
    @protocol UISceneDelegate
    

    其他属性修改:
    官方不再推荐使用 keywindow 属性


    Dark Mode 暗模式

    用Any Appearance变量指定要在不支持暗模式的旧系统上使用的颜色值
    兼容问题:
    1.没有设置背景色的 都变成 黑色了
    2.XIb 设置的黑色 字体,在该模式下变成白色了,然而我背景却是白色的,这样
    就感觉字消失了,原因是 xib 字体颜色为 【label color】这是新增的 颜色属性,(详情看下边的UIColor)改为你想要的颜色
    苹果解释:https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#dynamic-system-colors

    image.png

    如果想让APP保持原状态 plist 设置:


    image.png

    UIColor

    Label 颜色

    /* 包含主要内容的文本标签的颜色 */
    @property(class, nonatomic, readonly) UIColor *labelColor;
    /* 包含辅助内容的文本标签的颜色 */
    @property(class, nonatomic, readonly) UIColor *secondaryLabelColor;
    /* 包含第三级内容的文本标签的颜色 */
    @property(class, nonatomic, readonly) UIColor *tertiaryLabelColor;
    /* 包含四元内容的文本标签的颜色 */
    @property(class, nonatomic, readonly) UIColor *quaternaryLabelColor;
    

    填充色

    填充色 系统填充颜色包含透明度,以允许显示背景颜色

    /* 系统填充色 */
    @property(class, nonatomic, readonly) UIColor *systemFillColor;
    /* 使用此颜色填充中等大小的形状,例如开关的背景 */
    @property(class, nonatomic, readonly) UIColor *secondarySystemFillColor;
    /* 使用此颜色填充大型形状,例如输入字段,搜索栏或按钮 */
    @property(class, nonatomic, readonly) UIColor *tertiarySystemFillColor;
    /* 使用此颜色填充包含复杂内容的大区域,例如展开的表格单元格。 */
    @property(class, nonatomic, readonly) UIColor *quaternarySystemFillColor;
    

    其他

    不一一列举了,有点多,写几个以后会常用的吧

    /* 这啥颜色我也不想复制了,你懂得 */
    @property(class, nonatomic, readonly) UIColor *placeholderTextColor;
    /* 分割线颜色 */
    @property(class, nonatomic, readonly) UIColor *separatorColor;
    /* 隐藏任何基础内容的边框或分隔线的颜色 */
    @property(class, nonatomic, readonly) UIColor *opaqueSeparatorColor;
    /* 连接颜色 */
    @property(class, nonatomic, readonly) UIColor *linkColor;
    

    ******************* 崩溃信息 *******************

    注意:当前版本是测试版,只是给各位个参考,但不一定准确,具体要根据你的代码搞一搞

    1.[_LSDefaults sharedInstance]: unrecognized selector sent to class 0x1df510dd8
      定位:友盟统计 注册 key 时会报错,应该是不兼容问题,估计以后 友盟会更新兼容库
    
    2. UITextField * searchField = [_searchBar valueForKey:@"_searchField"];断点指示崩溃
    修改: _searchBar. searchTextField; 上边有注
    

    相关文章

      网友评论

        本文标题:iOS 13 更新内容与适配

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