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

前端 未结 7 1462
温柔的废话
温柔的废话 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:30

    I use the following snippet to push multiple View Controllers:

    extension UINavigationController {
        func push(_ viewControllers: [UIViewController]) {
            setViewControllers(self.viewControllers + viewControllers, animated: true)
        }
    
        // Also had this in here, left it in as a bonus :)
        func popViewControllers(_ count: Int) {
            guard viewControllers.count > count else { return }
            popToViewController(viewControllers[viewControllers.count - count - 1], animated: true)
        }
    }
    

提交回复
热议问题