iOS 18 TabBar 适配

2024-10-29  本文已影响0人  colhy
extension CustomerTabBarController: UITabBarControllerDelegate {

    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        UIView.setAnimationsEnabled(false)
        return true
    }

    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        UIView.setAnimationsEnabled(true)        
    }
}
image.png
google上查了,也没有好的解决方法。设置self.viewControllers的时候增加了两个UINavigationController()占位item,并在shouldSelect代理方法中对占位的item进行判断,不响应跳转,如果有更好的解决方法,欢迎评论留言
self.viewControllers = [navi1, UINavigationController(), navi2, UINavigationController(), navi3]

extension CustomerTabBarController: UITabBarControllerDelegate {

    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        UIView.setAnimationsEnabled(false)
        if let nav = viewController as? UINavigationController {
        if nav.viewControllers.isEmpty {
            return false
          }
        }        
        return true
    }

    func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        UIView.setAnimationsEnabled(true)        
    }
}
image.png
if UIDevice.current.userInterfaceIdiom == .pad {
    if #available(iOS 17.0, *) {
        traitOverrides.horizontalSizeClass = .compact
    } else {

    }
}

在iPad上显示传统样式

上一篇 下一篇

猜你喜欢

热点阅读