隐藏tabbar并删除空格

Utk*_*maz 39 uitabbar ios swift

有没有办法隐藏tabbar并删除剩余的空间(约50px)?

我试过了

self.tabBarController?.tabBar.hidden = true
self.extendedLayoutIncludesOpaqueBars = true
Run Code Online (Sandbox Code Playgroud)

没运气.我看到空白.

小智 60

如果您仍然在隐藏的标签栏下面看到黑色条纹,您是否尝试此处选择"在不透明条形下延伸边缘"

在此输入图像描述

还要确保仍然选择Under Bottom Bars.希望能帮助到你!

  • I used this But it doesn't work in swift 4 (6认同)

Ale*_*ano 34

斯威夫特3:

extension UITabBarController {
    func setTabBarVisible(visible:Bool, duration: TimeInterval, animated:Bool) {
        if (tabBarIsVisible() == visible) { return }
        let frame = self.tabBar.frame
        let height = frame.size.height
        let offsetY = (visible ? -height : height)

        // animation
        UIViewPropertyAnimator(duration: duration, curve: .linear) {
            self.tabBar.frame.offsetBy(dx:0, dy:offsetY)
            self.view.frame = CGRect(x:0,y:0,width: self.view.frame.width, height: self.view.frame.height + offsetY)
            self.view.setNeedsDisplay()
            self.view.layoutIfNeeded()
        }.startAnimation()
    }

    func tabBarIsVisible() ->Bool {
        return self.tabBar.frame.origin.y < UIScreen.main.bounds.height
    }
}
Run Code Online (Sandbox Code Playgroud)

使用(例如,如果selfUITabBarController):

self.setTabBarVisible(visible: false, duration: 0.3, animated: true)
Run Code Online (Sandbox Code Playgroud)

Swift 2.x:

extension UITabBarController {
    func setTabBarVisible(visible:Bool, duration: NSTimeInterval, animated:Bool) {
        if (tabBarIsVisible() == visible) { return }
        let frame = self.tabBar.frame
        let height = frame.size.height
        let offsetY = (visible ? -height : height)

        // animation
        UIView.animateWithDuration(animated ? duration : 0.0) {
            self.tabBar.frame = CGRectOffset(frame, 0, offsetY)
            self.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height + offsetY)
            self.view.setNeedsDisplay()
            self.view.layoutIfNeeded()
        }
    }

    func tabBarIsVisible() ->Bool {
        return self.tabBar.frame.origin.y < UIScreen.mainScreen().bounds.height
    }
}
Run Code Online (Sandbox Code Playgroud)

使用:

self.tabBarController?.setTabBarVisible(visible: false, duration: 0.3, animated: true)
Run Code Online (Sandbox Code Playgroud)

  • 我使用这种方法(非常相似的代码)具有可靠的性能直到iOS 10.我现在在iOS 11(Xcode 9 beta 6)中遇到了很多关于此代码的问题.当从另一个视图控制器返回到视图控制器时,视图的底部被从屏幕上拉出,并且标签栏从屏幕底部错误地偏移.是否有其他人在iOS 11中遇到此代码的问题?你找到了修复/替代方法吗? (2认同)
  • @AlessandroOrnano感谢您的关注。我也看到了物理设备的问题。我的视图控制器层次结构非常复杂。带有拆分视图控制器的选项卡视图控制器和带有容器视图的页面视图控制器等。这种方法现在在模拟器和物理潜水中都有很多问题。我正在把它拉到哪里,并在可能的情况下用替代方法替换它。:( (2认同)

JZA*_*ZAU 25

在评论中看到你的截图.我想你可以尝试设置hidesBottomBarWhenPushed为true.

hidesBottomBarWhenPushed = true
Run Code Online (Sandbox Code Playgroud)

或故事板.

在此输入图像描述

当您推送到另一个视图控制器时,它会自动隐藏底栏,并在您返回时再次显示.


Itu*_*ote 10

以编程方式,将其添加到下一个视图控制器以进行快速处理4。

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    tabBarController?.tabBar.isHidden = true
    edgesForExtendedLayout = UIRectEdge.bottom
    extendedLayoutIncludesOpaqueBars = true
}
Run Code Online (Sandbox Code Playgroud)

并添加背景色


Aja*_*mar 5

注意 - 此解决方案仅用于删除隐藏标签栏后留下的空白区域.

对于隐藏标签栏的最佳解决方案是 - @Michael Campsall 在这里回答

对此最简单的解决方案是更改视图(在我的情况下是tableView)底部约束,而不是使用BottomLayoutGuide给出底部约束,并使用superview.附上屏幕截图供参考.

下面的屏幕截图中显示的约束会产生问题,根据下一个屏幕截图进行更改.

根据以下屏幕截图更改此屏幕截图中显示的约束

删除空格的实际约束应该根据此(下面)截图.

在此输入图像描述