CNLiveBaseViewController.swift 1.81 KB
//
//  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
        }
    }
}