Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...