一、UINavigationBar与UITabBar在页面内容(ScrollView)没有与其相交时为透明状态

    iOS 15开始用UINavigationBarAppearance和UITabBarAppearance设置UINavigationBar与UITabBar,UINavigationBar与UITabBar都有scrollEdgeAppearance和standardAppearance两个属性,scrollEdgeAppearance控制页面没有与其相交的状态,standardAppearance控制页面内容与其相交的状态,如下设置不透明纯色的UINavigationBar与UITabBar:

navigationBar.tintColor = UIColor.white
navigationBar.isTranslucent = false
if #available(iOS 15.0, *) {
    let appearance = UINavigationBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundColor = UIColor.blue
    appearance.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16.5) as Any, NSAttributedString.Key.foregroundColor: UIColor.white]
    appearance.largeTitleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16.5) as Any, NSAttributedString.Key.foregroundColor: UIColor.white]
    appearance.backgroundImage = UIImage()
    appearance.shadowImage = UIImage()
    navigationBar.standardAppearance = appearance
    navigationBar.scrollEdgeAppearance = appearance
} else {
    navigationBar.barTintColor = UIColor.blue
    navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16.5) as Any, NSAttributedString.Key.foregroundColor: UIColor.white]
    navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationBar.shadowImage = UIImage()
}
tabBar.isTranslucent = false
if #available(iOS 15.0, *) {
    let appearance: UITabBarAppearance = UITabBarAppearance()
    appearance.configureWithOpaqueBackground()
    appearance.backgroundImage = UIImage()
    appearance.shadowImage = getImage(color: .gray)
    appearance.backgroundColor = .white
    tabBar.standardAppearance = appearance
    tabBar.scrollEdgeAppearance = appearance
} else {
    tabBar.backgroundImage = UIImage()
    tabBar.shadowImage = getImage(color: .gray)
    tabBar.tintColor = .blue
    tabBar.barTintColor = .white
}
/// 用UIColor生成UIImage
func getImage(color:UIColor, rect: CGRect = CGRect(x: 0, y: 0, width: 1.0, height: 1.0))->UIImage{
    UIGraphicsBeginImageContext(rect.size)
    let context:CGContext = UIGraphicsGetCurrentContext()!
    context.setFillColor(color.cgColor)
    context.fill(rect)
    let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    return image
}

    可以在viewController中设置UITabBarItem的样式:

let font = UIFont.systemFont(ofSize: 10)
if #available(iOS 15.0, *) {
    let appearance: UITabBarAppearance = tabBar.standardAppearance
    appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.gray,NSAttributedString.Key.font: font]
    appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue,NSAttributedString.Key.font: font]
    appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -2)
    appearance.stackedLayoutAppearance.selected.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -2)
    vc.tabBarItem.standardAppearance = appearance
    vc.tabBarItem.scrollEdgeAppearance = appearance
} else {
    vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.gray,NSAttributedString.Key.font: font], for: .normal)
    vc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.blue,NSAttributedString.Key.font: font], for: .highlighted)
    vc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -2)
}

    具体可参考外网彼得潘的文章(需FQ):

    https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E5%95%8F%E9%A1%8C%E8%A7%A3%E7%AD%94%E9%9B%86/ios-15-navigation-bar-tab-bar-%E7%9A%84%E6%A8%A3%E5%BC%8F%E8%A8%AD%E5%AE%9A-558f07137b52

    这是对这一iOS 15特性以及appearance描述较详细易懂的文章。

    对于UINavigationBar为白底黑字的app,这一特性可能影响不大,看情况适配。

 

二、UILabel显示的文字比设置font小

    在iOS 15中,UILabel 设置adjustsFontSizeToFitWidth为true时,高度不能跟设置的 font 一样大(具体需要大多少没研究,加大到能正常显示就行)。

 

三、固定宽度的UILabel文字显示不全

    在iOS 15以下计算的正好显示完UILabel文字的宽度,在iOS 15上可能显示不全,增加宽度即可。

 

四、UITableView 设置 tableHeaderView 后,底部会增加一段高度

    如果UITableView设置了tableHeaderView而没有设置tableFooterView,可能会出现这个问题,不确定是否是beta版的bug,解决方案是在设置tableHeaderView时同时设置一个高度为0.01的tableFooterView即可:

tableView?.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 0.01))

    设置这句代码后,之后在把tableFooterView设置为nil或者其他UIView都不影响。

 

五、plain类型的UITableView增加默认的section高度

    UITableView新增了一个新属性:sectionHeaderTopPadding,默认值为automaticDimension,当我们使用UITableViewStylePlain 初始化tableView的时候,sectionHeaderTopPadding会给section header默认增加高度,解决方案是把sectionHeaderTopPadding属性设置为0即可:

if #available(iOS 15.0, *) {
    tableView?.sectionHeaderTopPadding = 0
}

 

六、使用layoutIfNeeded更新tableHeaderView的frame没有生效

    使用StoryBoard搭建tableView,tableHeaderView的需要适配屏幕尺寸而呈现不同的高度,此时改变tableHeaderView的frame并调用layoutIfNeeded方法不会生效,tableHeaderView的高度虽然改变,但是UITableView的布局不变,解决方案是重新给tableHeaderView赋值:

DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
    if let headerView = self.tableView?.tableHeaderView, let lastSubView = headerView.subviews.last {
        if #available(iOS 15.0, *) {
            headerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: lastSubView.frame.origin.y + lastSubView.frame.size.height)
            self.tableView?.tableHeaderView = headerView
        } else {
            self.tableView?.tableHeaderView?.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: lastSubView.frame.origin.y + lastSubView.frame.size.height)
            self.tableView?.tableHeaderView?.layoutIfNeeded()
        }
    }
}

 

七、plain类型的UITableView默认不显示灰色section header 

    上滑置顶时最上面的section header才显示颜色,对于部分页面可能出现UI上的bug,解决方案是用viewForHeaderInSection代理方法返回带颜色的section header:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let sectionHeaderView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 20))
    sectionHeaderView.backgroundColor = UIColor.gray
    return sectionHeaderView
}

 

八、第三方播放器框架ZFPlayer横屏出现问题,没有正确渲染布局,且无法切回竖屏页面

    有几率闪退,模拟器和真机均有此情况,调试未发现原因,不确定是否是beta版的bug,可能需要等作者适配。

 

九、 部分h5在WKWebView无法显示

    现发现链接http://app.nnydlc.com:10080/newsinfo/newsDetail.action?newsId=1155&token=(null) 在iOS 15的WKWebView中无法显示,会直接显示空白页about:blank,在iOS 15的微信、QQ、Safari浏览器中同样显示空白页,但是iOS 15以下的版本正常;出现该问题的只有该服务器的h5,其他网页显示正常;该链接在Mac电脑中谷歌浏览器无法显示,显示端口不安全ERR_UNSAFE_PORT,Safari浏览正常(mac版本Big Sur 11.4,猜测升级到macOS Monterey beta 2会跟手机端一样显示空白页)。

    未找到解决方案,原因可能是iOS beta版bug或者该服务器或者h5的某些配置导致,可能不需要iOS端解决。

 

十、Facebook的跨平台框架React中的fishhook闪退

    解决方案是修改fishhook.c源码,参考https://github.com/facebook/fishhook/issues/85 中的XuweiQT的方案,将链接中的fishhook.c替换项目中fishhook.c文件。

 

十一、第三方BRPickerView文字选择器内容布局错误

    使用第三方BRPickerView的文本选择器,文字选项没有居中,最新版(2.7.5,2021-07-16)未见适配,解决方案:

    1.等待作者适配后再更新至最新版;

    2.自己写一个文本选项选择器,像日期选择、文本选择这么简单的东西就没必要用第三方了。