研究 navigation controller 的返回功能

Angie Wang
Jul 25, 2017 · 2 min read

首先建了兩個View Controller, 再嵌入Navigation Controller, 建立了兩個Bar Button Item, 分別是第一頁的Next跟第二頁的Back, 再從object library在兩個頁面都加入Swipe Gesture Recognizer, 在第一個頁面的Segue連結拉到下一個頁面做binding, 如下圖:

在回上一頁的Swipe手勢的Segue連結拉到前一頁, 設定如下圖:

接著在兩個Swipe Gesture Recognizer的Swipe屬性都設為Left, 即可做出由右向左滑可以到下一頁, 以及由左向右滑可以到上一頁的功能

[注意] 若是上一頁有設定標題, 則下一頁的按鈕「Back」會自動代換成上一頁的標題

模擬器畫面:

GitHub連結:

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade