Search code examples
swift

My UIViewcontroller is not filling the entire screen?


I have a very simple app with two UIviewcontrollers. I want to dismiss one and present another one. However, when I do this (code below), the second viewcontroller does not fill the screen, instead it hovers over the top one and can easily get dismissed if you swipe from the top down (you can just about see the first viewcontroller at the top)?

VC-1:

@objc private func picksAction(){
    print("picks button pressed")

    let layout = UICollectionViewFlowLayout()
    let viewController = GridPicksCollectionViewController(collectionViewLayout: layout)
    let navController = UINavigationController()
    navController.pushViewController(viewController, animated: true)
    self.present(navController, animated: true) {}

}

Result: enter image description here


Solution

  • Set modalPresentationStyle to .fullScreen:

    navController.modalPresentationStyle = .fullScreen