UITabBar 有问题
Having an issue with UITabBar
我已经尝试过文件检查器中的安全区域复选框。但效果不佳。又给我看这个问题。请问有什么完美的解决方案吗?
这是包含所有约束的图像。
尝试将约束的所有值设置为 0,我遇到了同样的问题图像会出现在标签上方或者图像不正确,
对于约束,如果要为顶部设置约束,则也需要为底部设置相同的约束...
希望对您有所帮助。
请取消tabbar的高度限制。因为 iPhone X 中的标签栏默认高度与其他 iPhone 设备不同。
希望对您有所帮助。
您可以使用此代码更新标签栏的高度
let ApplicationDelegate = UIApplication.shared.delegate as! AppDelegate
DispatchQueue.main.async {
if #available(iOS 11.0, *) {
if UIDevice().userInterfaceIdiom == .phone, ApplicationDelegate.window!.safeAreaInsets.top > 0 {
let kTabBarHeight: CGFloat = 49.0/*default tab bar height*/ + ApplicationDelegate.window!.safeAreaInsets.bottom
self.tabBar.frame = CGRect(x: 0, y: self.view.frame.size.height - kTabBarHeight, width: self.view.frame.size.width, height: kTabBarHeight);
}
}
}
希望对您有所帮助。
不要使用"loose"标签栏。您只能使用 UITabBarController 提供的标签栏。重构您的体系结构以使用 UITabBarController,并且选项卡栏在 iPhone X 上看起来是正确的(并且通常会正确调整大小,例如在 iPhone 上纵向比横向高)。
UITabBar controller不对图片添加任何约束,更新UITabbar的高度和iPhoneX的items。
`override func viewWillLayoutSubviews() {
var newTabBarFrame = tabBar.frame
var newTabBarHeight: CGFloat = 60
if UIDevice.current.iPhoneX{
newTabBarHeight = 102
}
newTabBarFrame.size.height = newTabBarHeight
newTabBarFrame.origin.y = self.view.frame.size.height - newTabBarHeight
tabBar.frame = newTabBarFrame
let numberOfItems = CGFloat(tabBar.items!.count)
let customColor = UIColor.lightGray.cgColor
let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: customColor, size: tabBarItemSize).resizableImage(withCapInsets: UIEdgeInsets.zero)
// remove default border
tabBar.frame.size.width = self.view.frame.width + 4
tabBar.frame.origin.x = -2
}`
我已经尝试过文件检查器中的安全区域复选框。但效果不佳。又给我看这个问题。请问有什么完美的解决方案吗?
这是包含所有约束的图像。
尝试将约束的所有值设置为 0,我遇到了同样的问题图像会出现在标签上方或者图像不正确, 对于约束,如果要为顶部设置约束,则也需要为底部设置相同的约束...
希望对您有所帮助。
请取消tabbar的高度限制。因为 iPhone X 中的标签栏默认高度与其他 iPhone 设备不同。
希望对您有所帮助。
您可以使用此代码更新标签栏的高度
let ApplicationDelegate = UIApplication.shared.delegate as! AppDelegate
DispatchQueue.main.async {
if #available(iOS 11.0, *) {
if UIDevice().userInterfaceIdiom == .phone, ApplicationDelegate.window!.safeAreaInsets.top > 0 {
let kTabBarHeight: CGFloat = 49.0/*default tab bar height*/ + ApplicationDelegate.window!.safeAreaInsets.bottom
self.tabBar.frame = CGRect(x: 0, y: self.view.frame.size.height - kTabBarHeight, width: self.view.frame.size.width, height: kTabBarHeight);
}
}
}
希望对您有所帮助。
不要使用"loose"标签栏。您只能使用 UITabBarController 提供的标签栏。重构您的体系结构以使用 UITabBarController,并且选项卡栏在 iPhone X 上看起来是正确的(并且通常会正确调整大小,例如在 iPhone 上纵向比横向高)。
UITabBar controller不对图片添加任何约束,更新UITabbar的高度和iPhoneX的items。
`override func viewWillLayoutSubviews() {
var newTabBarFrame = tabBar.frame
var newTabBarHeight: CGFloat = 60
if UIDevice.current.iPhoneX{
newTabBarHeight = 102
}
newTabBarFrame.size.height = newTabBarHeight
newTabBarFrame.origin.y = self.view.frame.size.height - newTabBarHeight
tabBar.frame = newTabBarFrame
let numberOfItems = CGFloat(tabBar.items!.count)
let customColor = UIColor.lightGray.cgColor
let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: customColor, size: tabBarItemSize).resizableImage(withCapInsets: UIEdgeInsets.zero)
// remove default border
tabBar.frame.size.width = self.view.frame.width + 4
tabBar.frame.origin.x = -2
}`