Push Up View Controller from Bottom using Swift

后端 未结 6 1294
一生所求
一生所求 2021-01-31 11:46

I would like to push a view controller using Swift and animate it so it appears from the bottom and moves up. I have the following code to push my view controller:



        
6条回答
  •  伪装坚强ぢ
    2021-01-31 12:43

    I had a similar situation where I needed to show a navigation item with some UIBarButtonItems on a view controller, but when presenting modally, it wasn't showing up. It was showing only when pushing from a navigationController, but I really needed the animation from bottom -> up. I tried the CATransition examples from above, but it brought up another bug where there was like a black shadow / translucent background during the animation. I came up with a pretty simple solution in the end:

    let someVC = storyboard?.instantiateViewController(withIdentifier: "SomeVC") as! SomeVC
    let navController = UINavigationController(rootViewController: someVC)
    navigationController?.present(navController, animated: true, completion: nil)
    

    And to close the view controller and get rid of the navigation controller altogether, you just call:

    self.dismiss(animated: true, completion: nil)
    

    This will dismiss the view controller, and will release our navigationController from memory.

    It is a simple solution in the end, but I spent some time until coming up with it. Maybe I'll save someone else's time :)

提交回复
热议问题