简体   繁体   English

标签栏重叠视图在后面

[英]Tab Bar overlap view behind

I can't seem to fix the issue about this where I adjusted the Tab Bar height to 60 from viewWillLayoutSubviews() but the overlay view doesn't seem to acknowledge the adjusted height and follow suit. 我似乎无法解决有关此问题的问题,在该问题中,我从viewWillLayoutSubviews()将Tab Bar的高度调整为60,但覆盖视图似乎无法确认调整后的高度并紧随其后。

Other similar questions I found are not actually alike (see here: iOS 7 Custom TableView Is Under TabBar ) as their Tab Bar is translucent, and mine's not. 我发现的其他类似问题实际上并不相同(请参见此处: iOS 7 Custom TableView位于TabBar下 ),因为它们的Tab栏是半透明的,而我的不是。

Here is what I implemented so far: 这是我到目前为止实现的:

In my custom UITabBarController : 在我的自定义UITabBarController

override func viewWillLayoutSubviews() {
    var newTabBarFrame = tabBar.frame
    let newTabBarHeight: CGFloat = 60
    newTabBarFrame.size.height = newTabBarHeight
    newTabBarFrame.origin.y = self.view.frame.size.height - newTabBarHeight
    tabBar.frame = newTabBarFrame
}

In one of my tab's UIViewController : 在我的标签的UIViewController

override func viewDidLoad() {
    view.addSubview(tableView)
    NSLayoutConstraint.activate([
        NSLayoutConstraint(item: tableView, attribute: NSLayoutAttribute.leading, relatedBy: .equal, toItem: view, attribute: NSLayoutAttribute.leading, multiplier: 1, constant: 0),
        NSLayoutConstraint( item: tableView, attribute: NSLayoutAttribute.top, relatedBy: .equal, toItem: view, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: tableView, attribute: NSLayoutAttribute.trailing, relatedBy: .equal, toItem: view, attribute: NSLayoutAttribute.trailing, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: tableView, attribute: NSLayoutAttribute.bottom, relatedBy: .equal, toItem: view, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
        ])
}

This is the current result: 这是当前结果: 这里 You can see the overlay view is partially blocked. 您可以看到叠加视图被部分阻止。 This happens on all other tab's overlay view controller 这发生在所有其他选项卡的覆盖视图控制器上

BTW, I already make sure the tableview's translatesAutoresizingMaskIntoConstraints is set to false 顺便说一句,我已经确保tableview的translatesAutoresizingMaskIntoConstraints设置为false

You can use a custom UITabBar to do this. 您可以使用自定义的UITabBar来执行此操作。 Just override sizeThatFits(_:) to use your custom height: 只需覆盖sizeThatFits(_:)即可使用您的自定义高度:

class TabBar: UITabBar {

    private let height:CGFloat = 60

    override func sizeThatFits(_ size: CGSize) -> CGSize {
        var bottomSafeAreaInsets: CGFloat = 0
        if #available(iOS 11.0, *) {
            bottomSafeAreaInsets = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
        }
        return CGSize(width: size.width, height: height + bottomSafeAreaInsets)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM