What is the difference between Modal and Push segue in Storyboards?

前端 未结 4 517
别跟我提以往
别跟我提以往 2020-11-28 00:55

Can someone explain to me what is the exact difference between modal and push segue?

I know that when we use push the segue ge

4条回答
  •  借酒劲吻你
    2020-11-28 01:26

    Swift 3.0 and XCode 8.2.1 update

    1. Push Segue

    Push segue has been renamed as Show segue. To create push segue, the parent view controller needs to be embedded in navigation controller. The navigation controller provides navigation bar. Once you connect two view controller with push segue, the child view controller will automatically has navigation bar on top. The child view controller will be added on top of the navigation stack.

    Push segue also provides default features. The child view controller will have a back button that gets you back to the parent view controller. You can also swipe right to pop the child view controller. The animation for push segue is like sliding pages horizontally.

    While you are allowed to make a push segue from a view controller that is not in a navigation controller, you will lose all the features like navigation bar, animation, gesture etc when you do so. In this case, you should embed your parent view controller inside navigation view controller first and then make push segue to child view controllers.

    2. Modal Segue

    A modal segue (i.e. present modally), on the other hand, is presenting over the current view controller. The child view controller will not inherit navigation view controller so the navigation bar will be lost if you present modal segue from a view controller with navigation view controller. You have to embed the child view controller in navigation controller again and start a brand new navigation stack if you want it back. If you want to get back to parent view controller, you have to implement this by yourself and call dismiss from code.

    Animation for modal segue is that the child view controller will comes up from the bottom of the page. The navigation view controller is also gone in this demo

提交回复
热议问题