Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

ios - Custom TabBar layout for UITabBarViewController

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 scenes of the app.

Update:

I want to have a view at the bottom of the screen (above the tab bar) and under the content views of the different tabs (not above them). In addition, I want to have the ability to remove this view at a certain point making the main view take the whole screen.

I can do this using the mentioned Answer by changing the constraints of the nowPlaying view programmatically.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...