如何使用Nativescript中的滑动手势实现页面之间的导航

时间:2016-04-27 22:25:44

标签: navigation swipe nativescript

我想在页面之间实现导航,就像通过向左或向右滑动TabView一样。但是,对于页面级别或跨越整个屏幕的布局,似乎不会触发滑动手势。 TabView本身没用,因为我有一大堆用户可以滚动的项目,而且我不需要在屏幕上显示一堆标签。

有没有人知道如何在Nativescript中实现它?

2 个答案:

答案 0 :(得分:5)

StackOverflow和NatieScript的问候!整个屏幕上的布局元素是一个工作选项。

例如:

// main-page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:drawer="nativescript-telerik-ui/sidedrawer"  navigatingTo="navigatingTo" loaded="onLoaded">
    <StackLayout id="swipable">
        <Label text="Swipe to nabigate to next" textWrap="true" />  
    </StackLayout>
</Page>

// main-page.js
var stackModule = require("ui/layouts/stack-layout");
var gestures = require("ui/gestures");
var frameModule = require("ui/frame");
function onLoaded(args) {
    var page = args.object;

    var myStack = page.getViewById("swipable");
    myStack.on(gestures.GestureTypes.swipe, function (args) {
        frameModule.topmost().navigate({
            moduleName: "next-page"
        });
    });
}
exports.onLoaded = onLoaded;

答案 1 :(得分:0)

这对我有用

XML:

// XML
<ScrollView row="0" orientation="horizontal" swipe="onSwipe">
   .... content.... 
</ScrollView>

javascript:

// javascript
function onSwipe(args) {    
var direction = args.direction;
console.log("Swipe Direction: " + direction); // 1 - left, 2 - right

if(direction === 1) {
    //topmost = require("ui/frame").topmost;
    frameModule.topmost().goBack(); // replace with func. below for navigation to other page
       // frameModule.topmost().navigate({
       // moduleName: "your/page"
       //   });

  }
}

这不会显示任何视觉上的滑动动作(没有动画等)。

相关问题