Created
October 31, 2018 09:35
-
-
Save bawn/68e9c20caf785ba3ce20efd3d38a18a2 to your computer and use it in GitHub Desktop.
修复 iOS 12.1 上 UITabBar 里面的 items 偏移问题
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class HQTabBar: 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]}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
请问下有没有oc版的