gpt4 book ai didi

ios - 修改导航 Controller 中所有 ViewController 的高度

转载 作者:行者123 更新时间:2023-11-30 11:37:49 26 4
gpt4 key购买 nike

我有一个带有 4 个选项卡的选项卡栏 Controller 。每个选项卡都有一个导航 Controller 。

在某个时刻,一个 View (如播放器)会被添加到 TabBarController 的 tabBar 项目上方。

如何使所有 4 个导航 Controller 及其各自的 View 提高 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()
})
}

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

谢谢!

最佳答案

如果像这样创建 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

}

}

}

或者在 child 身上

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

}

}

}

关于ios - 修改导航 Controller 中所有 ViewController 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49556849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com