美文网首页
IOS15审核最新详细版

IOS15审核最新详细版

作者: 那位小姐 | 来源:发表于2021-09-23 10:38 被阅读0次

    IOS15适配

    导航栏UINavigationBar
    • 从 iOS 15 开始,UINavigationBar、UIToolbar 和 UITabBar 在控制器中关联滚动视图顶部或底部时使用 在iOS15中,UINavigationBar默认是透明的,有滑动时会逐渐变为模糊效果,可以通过改变 UINavigationBar.scrollEdgeAppearance属性直接变为模糊效果、配置相关属性-背景、字体等
    //ios15之前设置
    navigationBar.setBackgroundImage(UIColor.clear.image, for: .default) // 导航栏背景,主题色是绿色
    navigationBar.barTintColor = UIColor.theme // 默认不透明
     navigationBar.isTranslucent = false // 着色,让返回按钮图片渲染为白色 
     navigationBar.tintColor = UIColor.white // 导航栏文字 
     navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18), NSAttributedString.Key.foregroundColor: UIColor.white ]
    
    • iOS15更新 navigationBar的相关属性设置要通过实例UINavigationBarAppearance来实现,UINavigationBarAppearance是iOS13更新的API,应该有人已经在用,我们的应用兼容iOS10以上,对于导航栏的设置还没有使用UINavigationBarAppearance,如今在iOS15上失效,所以对于呈现的问题,做如下适配:
    ......
    if #available(iOS 15, *) {
        let app = UINavigationBarAppearance.init()
        app.configureWithOpaqueBackground()  // 重置背景和阴影颜色
        app.titleTextAttributes = [
            NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18),
            NSAttributedString.Key.foregroundColor: UIColor.white
        ]
        app.backgroundColor = UIColor.theme  // 设置导航栏背景色
        app.shadowImage = UIColor.clear.image  // 设置导航栏下边界分割线透明
        navigationBar.scrollEdgeAppearance = app  // 带scroll滑动的页面
        navigationBar.standardAppearance = app // 常规页面
    }
    ......
    
    TableView滚动列表
    • 从 iOS 15 开始,TableView 增加sectionHeaderTopPadding属性,它的默认值是UITableViewAutomaticDimension,所以我们要将他设置为0,否则当我们的列表设置了section高度的列表会出现head高度增加的情况,sectionHeaderTopPadding会有22个像素的高度,适配方式:
    /// Padding above each section header. The default value is `UITableViewAutomaticDimension`.
     @available(iOS 15.0, *) open var sectionHeaderTopPadding: CGFloat
     
    if #available(iOS 15.0, *){ 
    self.tableView.sectionHeaderTopPadding = 0 
    }
    
    
    UITabbar
    • tabbar的问题和navigationBar的问题属于同一类,tabbar背景颜色设置失效,字体设置失效,阴影设置失效问题(旧代码如下:)
    ......
    self.tabBar.backgroundImage = UIColor.white.image
    self.tabBar.shadowImage = UIColor.init(0xEEEEEE).image
    item.setTitleTextAttributes(norTitleAttr, for: .normal)
    item.setTitleTextAttributes(selTitleAttr, for: .selected)
    ......
    
    • 首先是背景色设置失效,让我就想到了navigationbar的问题,所以没有查api了直接用UITabBarAppearance来设置,解决方案如下:
    if #available(iOS 15, *) { 
    let bar = UITabBarAppearance.init() 
    bar.backgroundColor = UIColor.white 
    bar.shadowImage = UIColor.init(0xEEEEEE).image 
    let selTitleAttr = [ 
        NSAttributedString.Key.font: itemFont, 
        NSAttributedString.Key.foregroundColor: UIColor.theme 
    ] 
    bar.stackedLayoutAppearance.selected.titleTextAttributes = selTitleAttr // 设置选中attributes 
    self.tabBar.scrollEdgeAppearance = bar 
    self.tabBar.standardAppearance = bar 
    }
    
    Image
    • 在iOS15中,UIImageWriteToSavedPhotosAlbum存储图片之后的回调不再返回图片了,会返回nil,如果在回调方法里面操作image有可能会直接Crash,目前的解决办法声明一个全局image去记录,后面再去操作
    self.image = image; 
    UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:didFinishSavingWithError:contextInfo:), NULL);
     - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ 
     // self.image doing... 
     }
    
    
    • UIImage 新增了几个调整尺寸的方法。
    // preparingThumbnail 
    UIImage(named: "sv.png")?.preparingThumbnail(of: CGSize(width: 200, height: 100)) // prepareThumbnail,闭包中直接获取调整后的UIImage
     UIImage(named: "sv.png")?.prepareThumbnail(of: CGSize(width: 200, height: 100)) { 
      // image in需要回到主线程更新UI 
      } // byPreparingThumbnail 
     await UIImage(named: "sv.png")?.byPreparingThumbnail(ofSize: CGSize(width: 100, height: 100))
    
    

    剩余API的完善

    • 对状态编程的支持:UICellConfigurationState;UICollectionViewCell、UITableViewCell都支持状态变化时的block执行了。

    • UICollectionViewLayout支持自动高度;AutomaticDimension

    • json解析支持json5了

    • 增加UISheetPresentationController,通过它可以控制 Modal 出来的 UIViewController 的显示大小,且可以通过拖拽手势在不同大小之间进行切换。只需要在跳转的目标 UIViewController 做如下处理:
      if let presentationController = presentationController as? UISheetPresentationController { // 显示时支持的尺寸
      presentationController.detents = [.medium(), .large()] // 显示一个指示器表示可以拖拽调整大小
      presentationController.prefersGrabberVisible = true
      }

    • UIButton支持更多配置。UIButton.Configuration是一个新的结构体,它指定按钮及其内容的外观和行为。它有许多与按钮外观和内容相关的属性,如

    cornerStyle、baseForegroundColor、baseBackgroundColor、buttonSize、title、image、subtitle、titlePadding、imagePadding、contentInsets、imagePlacement等。
    // Plain 
    let plain = UIButton(configuration: .plain(), primaryAction: nil) plain.setTitle("Plain", for: .normal) // Gray 
    let gray = UIButton(configuration: .gray(), primaryAction: nil) gray.setTitle("Gray", for: .normal) // Tinted
     let tinted = UIButton(configuration: .tinted(), primaryAction: nil) tinted.setTitle("Tinted", for: .normal) // Filled 
     let filled = UIButton(configuration: .filled(), primaryAction: nil) filled.setTitle("Filled", for: .normal) 
    
    
    • 推出CLLocationButton用于一次性定位授权,该内容内置于CoreLocationUI模块,但如果需要获取定位的详细信息仍然需要借助于CoreLocation。
    let locationButton = CLLocationButton() // 文字 
    locationButton.label = .currentLocation locationButton.fontSize = 20 // 图标 
    locationButton.icon = .arrowFilled // 圆角
    locationButton.cornerRadius = 10 //
    tint locationButton.tintColor = UIColor.systemPink // 背景色 
    locationButton.backgroundColor = UIColor.systemGreen // 点击事件,应该在在其中发起定位请求 
    locationButton.addTarget(self, action: #selector(getCurrentLocation), for: .touchUpInside)
    
    • URLSession 推出支持 async/await 的 API,包括获取数据、上传与下载。
    // 加载数据 
    let (data, response) = try await URLSession.shared.data(from: url) // 下载 
    let (localURL, _) = try await session.download(from: url) // 上传 
    let (_, response) = try await session.upload(for: request, from: data)
    
    • 系统图片支持多个层,支持多种渲染模式。
    // hierarchicalColor:多层渲染,透明度不同 
    let config = UIImage.SymbolConfiguration(hierarchicalColor: .systemRed)
    let image = UIImage(systemName: "square.stack.3d.down.right.fill", withConfiguration: config) // paletteColors:多层渲染,设置不同风格 
    let config2 = UIImage.SymbolConfiguration(paletteColors: [.systemRed, .systemGreen, .systemBlue])
    let image2 = UIImage(systemName: "person.3.sequence.fill", withConfiguration: config2)
    

    本文借鉴与大佬的辛苦制作

    相关文章

      网友评论

          本文标题:IOS15审核最新详细版

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