Reputation: 373
I have a CollectionView from where I have a modal segue (going fullscreen) to a TabBarController. In the middle of the tabBar from the TabBarController is a UIButton which pushes a modal view above the TabBarController (not fullscreen). After the modal view pushed from the TabBarController got dismissed, the UIButton disappears in the tabBar (as seen in the pictures)
before opening modal view
after dismissal
This does not happen, when the second modally presented ViewController is shown fullscreen. The following setup works fine:
CollectionView --modal fullscreen--> TabBarController --modal fullscreen--> anotherViewController
This also doesn't happen, when I embed the first VC in a NavigationController and push the TabBarController within the navigationstack. This here works also as expected:
NavigationView(CollectionView) --pushes--> TabBarController --modal--> anotherViewController
The problem is only showing, when I present a ViewController modally, not fullscreen, above another modally shown ViewController. And now I want to understand why this is happening.
This is how I set up my TabBar:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
setupTabBarAppearance()
setupTabBarShadow()
setupTabBar()
}
private func setupTabBar() {
middleButtonView.center = CGPoint(x: tabBar.frame.width / 2, y: 10)
middleButton.center = CGPoint(x: middleButtonView.frame.width / 2, y: middleButtonView.frame.width / 2)
middleButtonView.addSubview(middleButton)
tabBar.addSubview(middleButtonView)
}
This is how I present the ModalViewController:
@objc private func showController() {
let viewController = TableViewController()
viewController.modalPresentationStyle = .automatic
self.present(viewController, animated: true)
}
I dismiss the presented ViewController within the presented Controller:
@objc func dismissController(){
self.dismiss(animated: true, completion: nil)
}
I'm thankful for any help provided
Upvotes: 0
Views: 81
Reputation: 373
Changing the constraints did help. My setup looks like this right now and it works like a charm. Thanks to Lucas for the idea! But I still don't know why the change was needed anyways.
private func setupTabBar() {
middleButtonView.addSubview(middleButton)
tabBar.addSubview(middleButtonView)
middleButtonView.centerXAnchor.constraint(equalTo: tabBar.centerXAnchor, constant: 0).isActive = true
middleButtonView.centerYAnchor.constraint(equalTo: tabBar.centerYAnchor, constant: -30).isActive = true
middleButtonView.heightAnchor.constraint(equalToConstant: buttonViewRadius * 2).isActive = true
middleButtonView.widthAnchor.constraint(equalToConstant: buttonViewRadius * 2).isActive = true
middleButton.centerYAnchor.constraint(equalTo: middleButtonView.centerYAnchor, constant: 0).isActive = true
middleButton.centerXAnchor.constraint(equalTo: middleButtonView.centerXAnchor, constant: 0).isActive = true
middleButton.heightAnchor.constraint(equalToConstant: buttonRadius * 2).isActive = true
middleButton.widthAnchor.constraint(equalToConstant: buttonRadius * 2).isActive = true
}
Upvotes: 1