我注意到,弹出UITabBarController包含网络视图时,UIViewController选项卡栏的高度将被压缩,然后在iOS 12设备中返回UITabBarController。像这样:

ios - 弹出UIWebViewController然后返回UITabBarController时,选项卡栏的高度将发生变化-LMLPHP

我该如何解决?

最佳答案

使用此

import UIKit

class FixedTabBar: UITabBar {

    var itemFrames = [CGRect]()
    var tabBarItems = [UIView]()


    override func layoutSubviews() {
        super.layoutSubviews()

        if itemFrames.isEmpty, let UITabBarButtonClass = NSClassFromString("UITabBarButton") as? NSObject.Type {
            tabBarItems = subviews.filter({$0.isKind(of: UITabBarButtonClass)})
            tabBarItems.forEach({itemFrames.append($0.frame)})
        }

        if !itemFrames.isEmpty, !tabBarItems.isEmpty, itemFrames.count == items?.count {
            tabBarItems.enumerated().forEach({$0.element.frame = itemFrames[$0.offset]})
        }
    }
}

关于ios - 弹出UIWebViewController然后返回UITabBarController时,选项卡栏的高度将发生变化,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53221812/

10-11 14:01