Custom TabBar layout for UITabBarViewController

前端 未结 2 760
悲哀的现实
悲哀的现实 2020-12-12 04:47

Please refer to this Answer.

I am trying to do the same thing, however I want to do this in a Tab Bar App where the Now Playing bar is above the Tab Bar in all the s

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 05:12

    Using UITabBarViewController subclass it is possible:

    Ex:

    class DashBoardViewController: UITabBarController {
    
        let nowPlayingBar:UIView = {
            let view = UIView(frame: .zero)
            view.backgroundColor = .blue
            return view
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
            initView()
        }
    
        override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            nowPlayingBar.frame = tabBar.frame
        }
    
        override func viewDidAppear(_ animated: Bool) {
            var newSafeArea = UIEdgeInsets()
    
            // Adjust the safe area to accommodate
            //  the height of the bottom views.
            newSafeArea.bottom += nowPlayingBar.bounds.size.height
    
            // Adjust the safe area insets of the
            //  embedded child view controller.
            self.childViewControllers.forEach({$0.additionalSafeAreaInsets = newSafeArea})
        }
    
        private func initView() {
            nowPlayingBar.frame = tabBar.frame
            view.addSubview(nowPlayingBar)
        }
    }
    

提交回复
热议问题