CNLiveBaseViewController.swift
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
// CNLiveBaseViewController.swift
// metaCode
//
// Created by open on 2023/5/30.
//
import UIKit
import Foundation
class CNLiveBaseViewController: UIViewController {
deinit {
log("主界面已销毁")
}
override func viewDidLoad() {
self.view.backgroundColor = .white
configIOS11()
configIOS15()
self.navigationController?.isNavigationBarHidden = true
}
// MARK: - iOS 适配
func configIOS11() {
/// 适配 iOS 11.0 ,iOS11以后,控制器的automaticallyAdjustsScrollViewInsets已经废弃,所以默认就会是YES
/// iOS 11新增:adjustContentInset 和 contentInsetAdjustmentBehavior 来处理滚动区域
if #available(iOS 11.0, *) {
UITableView.appearance().estimatedRowHeight = 0
UITableView.appearance().estimatedSectionHeaderHeight = 0
UITableView.appearance().estimatedSectionFooterHeight = 0
// 防止列表/页面偏移
UIScrollView.appearance().contentInsetAdjustmentBehavior = .never
UITableView.appearance().contentInsetAdjustmentBehavior = .never
UICollectionView.appearance().contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
}
func configIOS15() {
// 适配iOS15,tableView的section设置
// iOS15中,tableView会给每一个section的顶部(header以上)再加上一个22像素的高度,形成一个section和section之间的间距
// 新增的sectionHeaderTopPadding会使表头新增一段间隙,默认为UITableViewAutomaticDimension
if #available(iOS 15.0, *) {
UITableView.appearance().sectionHeaderTopPadding = 0
}
}
}