1

I notice that the height of UITabBarController tab bar will be compressed when pop a UIViewController contains a web view and then back to UITabBarController in iOS 12 devices. Like this:

enter image description here

How can I fix that?

Mateusz
  • 698
  • 1
  • 8
  • 18
ZeroOnet
  • 15
  • 7

1 Answers1

2

Use this

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]})
        }
    }
}
B2Fq
  • 876
  • 1
  • 8
  • 23