UITabBar items jumping on back navigation on iOS 12.1

后端 未结 12 987
北恋
北恋 2020-11-29 18:28

I have an iOS app with UITabBarController on a master screen, navigating to a detail screen hiding the UITabBarController with setting hidesB

12条回答
  •  萌比男神i
    2020-11-29 18:44

    Here's a solution that can handle rotation and tab bar items being added or removed:

    class FixedTabBar: UITabBar {
    
        var buttonFrames: [CGRect] = []
        var size: CGSize = .zero
    
        override func layoutSubviews() {
            super.layoutSubviews()
    
            if UIDevice.current.systemVersion >= "12.1" {
                let buttons = subviews.filter {
                    String(describing: type(of: $0)).hasSuffix("Button")
                }
                if buttonFrames.count == buttons.count, size == bounds.size {
                    zip(buttons, buttonFrames).forEach { $0.0.frame = $0.1 }
                } else {
                    buttonFrames = buttons.map { $0.frame }
                    size = bounds.size
                }
            }
        }
    }
    

提交回复
热议问题