IOS15审核最新详细版

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)

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容