【问题标题】:Modify height all ViewControllers in a Navigation Controller修改导航控制器中所有视图控制器的高度
【发布时间】:2018-09-08 10:58:58
【问题描述】:

我有一个带有 4 个标签的标签栏控制器。每个选项卡都有一个导航控制器。

在某个时刻,一个视图(就像一个播放器)被添加到 TabBarController 就在 tabBar 项目的上方。

如何使所有 4 个导航控制器及其各自的视图提升 40pt?

我尝试了很多东西,但没有成功。

tabBar类:

UIView.animate(withDuration: Constants.TAB_BAR_ANIMATION_DURATION, animations: { [weak self] in
self?.view?.alpha = 1
self?.viewcontainer.frame = CGRect(x:0, y:UIScreen.main.bounds.height - (self?.tabbarHeight)! - Constants.viewHeight, width:UIScreen.main.bounds.width, height:Constants.viewHeight)
self?.view?.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:Constants.viewHeight)
    }){[weak self] _ in
       self?.viewcontainer.layoutSubviews()
       self?.childViewControllers.forEach({ (vc) in
       vc.navigationController?.view.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:UIScreen.main.bounds.height - 40)
       vc.navigationController?.view.layoutIfNeeded()
    })
}

最后一部分是问题。还尝试更改视图的高度,但没有找到解决方案。

谢谢!

【问题讨论】:

    标签: ios swift uiview uitabbarcontroller containers


    【解决方案1】:

    如果像这样创建 tabBarController 的自定义类,您可以完成此操作,但请记住,如果选项卡后面没有其他 ViewController,背景将是黑色的

    class CusTabViewController: UITabBarController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
    
    
        override func viewDidAppear(_ animated: Bool) {
    
            UIView.animate(withDuration: 4 , animations: { [weak self] in
    
                self?.view.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:100 )
    
    
            }){[weak self] _ in
    
            }
    
        }
    
    }
    

    或者在孩子身上

    class FirstViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
        }
    
        @IBAction func dd(_ sender: Any) {
    
            UIView.animate(withDuration: 4 , animations: { [weak self] in
    
                self?.view.frame = CGRect(x:0, y:0, width:UIScreen.main.bounds.width, height:(self?.view.frame.height)! - 200)
    
    
            }){[weak self] _ in
    
            }
    
        }
    
    }
    

    【讨论】:

    • 试过你的第二个例子,但这会提升我的tabBar。我需要一些东西来最小化 tabBar 中包含的视图(孩子的视图)
    • 非常感谢。我使用编辑后的代码并将其放入 viewDidAppear 中,并检查视图是否实际显示并且是否有效。缺点是我需要为所有导航控制器中的所有孩子执行此操作。我现在将使用它,但如果您有其他建议,请告诉。我会接受你的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多