0
votes

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

before opening modal view

after dismissal

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

1
This won't be that much help, but awhile ago I had the same problem and I fixed it by deleting my constraints and adding them back.Lucas Dahl
I made my setup programmatically so this probably won’t help me. But thanks for the ideabaronfac
You can still add constraints programmatically.Lucas Dahl
I'm glad you insisted. After adding the constraints in a different way (centerY, X, height and width) it did work. I still have no idea why it made those problems but: solved. Cheers mate!baronfac
I never figured out why it did that either, but I do know how to fix it.Lucas Dahl

1 Answers

1
votes

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
    
}