我有一个带有4个标签的标签栏控制器。每个选项卡都有一个导航控制器。
在某个时刻,视图(如播放器)被添加到tabBar项目正上方的TabBarController中。
如何将所有4个导航控制器及其各自的视图提升40pt?
我尝试了很多东西,但没有成功。
tabBarClass:
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()
})
}
最后一部分是问题所在。尝试也改变了视图的高度,但没有得到解决方案。
谢谢!
答案 0 :(得分:0)
如果像这样创建了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
}
}
}