Swift - 适配iOS 11,部分问题

1. iPhone X tabbar 高度为 83 ,其余机型为49;  导航栏+状态高度为 88,其余为64

官方适配标准如下图:


2. UITableview 顶部出现留白

解决方法: 添加以下代码

[objc] view plain copy
  1. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {  
  2.     return nil  
  3. }  
  4. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {  
  5.     return nil  
  6. }  

3. iOS 11 弃用 automaticAdjustsScrollViewInsets 新增 contentInsetAdjustmentBehavior

[objc] view plain copy
  1. if #available(iOS 11.0, *) {  
  2.     tableView.contentInsetAdjustmentBehavior = .never  
  3. else {  
  4.     self.automaticallyAdjustsScrollViewInsets = false  
  5. }  


4. Xcode9向UIapplication 报告主线程调用 :[UIApplication statusBarOrientation]

[objc] view plain copy
  1. Main Thread Checker: UI API called on a background thread: -[UIApplication statusBarOrientation]  
  2. PID: 22810, TID466328, Thread name: (none), Queue name: WriteLogQueue, QoS0  
  3. Backtrace:  
  4. 4   Numerology                          0x0000000107a99468 -[SSDKContext screenResolution] + 88  
  5. 5   Numerology                          0x0000000107aae942 +[SSDKLog encryptDeviceString] + 390  
  6. 6   Numerology                          0x0000000107aa6900 __28-[SSDKRunLog getLogContent:]_block_invoke + 59  
  7. 7   Numerology                          0x0000000107aae769 -[SSDKLog getLogContent:] + 654  
  8. 8   Numerology                          0x0000000107aa68a6 -[SSDKRunLog getLogContent:] + 127  
  9. 9   Numerology                          0x0000000107ac9523 __28-[SSDKLogService sendRunLog]_block_invoke + 138  
  10. 10  libdispatch.dylib                   0x00000001115df3f7 _dispatch_call_block_and_release + 12  
  11. 11  libdispatch.dylib                   0x00000001115e043c _dispatch_client_callout + 8  
  12. 12  libdispatch.dylib                   0x00000001115e895b _dispatch_queue_serial_drain + 1162  
  13. 13  libdispatch.dylib                   0x00000001115e92df _dispatch_queue_invoke + 336  
  14. 14  libdispatch.dylib                   0x00000001115e507d _dispatch_queue_override_invoke + 733  
  15. 15  libdispatch.dylib                   0x00000001115ec1f9 _dispatch_root_queue_drain + 772  
  16. 16  libdispatch.dylib                   0x00000001115ebe97 _dispatch_worker_thread3 + 132  
  17. 17  libsystem_pthread.dylib             0x0000000111a9c5a2 _pthread_wqthread + 1299  
  18. 18  libsystem_pthread.dylib             0x0000000111a9c07d start_wqthread + 13  

解决方法: 取消勾选部分




5.  关于嵌套tableview后,刷新列表,导致列表向上偏移的问题

原因: iOS 8  引入了Self-Sizing后,我们可以通过estimatedRowHeight来估算每个cell的高度。iOS11 Self-Sizing 默认开启,estimatedRowHeight会由之前的 0 改变为UITableViewAutomaticDimension, 之前项目中,没有使用estimatedRowHeight,在刷新列表的时候,会重新计算 contentSize,进而影响到contentOffSet

解决方法: 
[objc] view plain copy
  1. tableView.estimatedRowHeight = 0.0  
  2. tableView.estimatedSectionFooterHeight = 0.0  
  3. tableView.estimatedSectionHeaderHeight = 0.0  


6. 关于iOS 11 新特性: 大标题prefersLargeTitles

显示大标题 

[objc] view plain copy
  1. navigationController.navigationBar.prefersLargeTitles = true  
修改大标题颜色,字号等

[objc] view plain copy
  1. navigationController.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.orange,  
  2.                                                                                 NSAttributedStringKey.font: UIFont.systemFont(ofSize: 36)]  
大标题显示样式

[objc] view plain copy
  1. navigationItem.largeTitleDisplayMode = .automatic  

此处说明一下显示样式,默认显示样式为automatic:由前一个界面的设置的显示样式决定。 always:不管其他界面,如何设置,当前只要设置样式为always,则一直显示大标题,不会因界面滚动而显示小标题。  never:与always相反,一直显示小标题


如果想看更多 Swift 相关的文章可以去 LJ_Y 的博客转一转,此文章也转自其博客:

https://blog.csdn.net/a645258072/article/details/78040849


猜你喜欢

转载自blog.csdn.net/siwen1990/article/details/79988382
今日推荐