简体   繁体   中英

Swipe Left to go Back

With OnsenUI 1.10, is there a way to swipe left to go to the previous page?

With OnsenUI, the app can look very native, however, the swipe-left iOS 7 gesture is important for my user experience.

I saw this: http://www.idangero.us/framework7/dist/ where the user can swipe left to go to the previous page. (On a desktop environment, you can drag from left to right)

Any ideas?

One solution is to use Hammer included in Onsen UI. You can trap the gesture and do actions. For example,

 ons.bootstrap();
 Hammer(window, {prevent_default:true} ).on("swiperight",function(event) { 
    if (myNavigator.getPages().length > 1) {
        myNavigator.popPage();
    }
 });

where the myNavigator is defined as

<ons-navigator title="Navigator" var="myNavigator" page="page1.html">
</ons-navigator> 

Note that in the above example, we do not use AngularJS's Controller and directly access the Navigator. This is a new feature of Onsen UI 1.1.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM