How to push two view controllers but animate transition only for the second one?

前端 未结 7 1468
温柔的废话
温柔的废话 2020-12-04 17:46

I have three controllers (FirstVC, SecondVC, ThirdVC) inside storyboad, and navigation is sequential: a user can navigate from FirstVC to SecondVC, and then to ThirdVC. Now,

7条回答
  •  不知归路
    2020-12-04 18:20

    Swift Version From KimAMartinsen Solution

    guard var controllers = self.navigationController?.viewControllers else {
       return
    }
    
    guard let firstVC = self.storyboard?.instantiateViewController(withIdentifier: "Tests") as? firstViewController else { 
       return
    }
    
    guard let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "Dashboard") as? SecondViewController else {
        return
    }
    
    controllers.append(firstVC)
    controllers.append(secondVC)
    self.navigationController?.setViewControllers(controllers, animated: true)
    

提交回复
热议问题