【问题标题】:in Listview while scrolling and fast click on item unable to stop scroll, intead it will open a item?在 Listview 中滚动和快速单击项目时无法停止滚动,它会打开一个项目吗?
【发布时间】:2016-04-28 14:44:09
【问题描述】:

在列表视图里面我有列表视图模板,它里面有不同的元素和不同的点击事件监听器。

在 IOS 中快速滚动和快速触摸屏幕。 它导航到项目页面而不是停止滚动,所以我想接近下面的方法来停止滚动。无法修复。

预期结果:停止滚动 如果触摸屏幕停止滚动,然后我触摸屏幕打开项目页面。

实际结果:进入 els 部分,无法停止滚动。 在屏幕上滚动触摸时(触发点击事件)而不是停止滚动。

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
  <ListView items="{{ menu }}" row="1"  id="mylist" >
    <ListView.itemTemplate>
      <GridLayout columns="auto, *">
        <Image src="{{ imageURL }}" row="0" cssClass="icon" tap="myTapListener"/>
        <StackLayout col="1" tap="myTapListener1">
          <Label text="{{ title }}"  cssClass="name"/>
          <Label text="{{ subtitle }}" cssClass="location"/>
        </StackLayout>
      </GridLayout>
    </ListView.itemTemplate> 
  </ListView>
</Page



 exports.myTapListener = function(args) {
    var item = args.object;
    if(item.page.getViewById("mylist").isScrolling) {
        console.log("Scroll stopped: " + item.page.getViewById("mylist).isScrolling);
        return;
    } else {
        console.log("unable to stop:" + item.page.getViewById("mylist).isScrolling);
    }
}

exports.myTapListener1 = function(args) {
    var item = args.object;
    if(item.page.getViewById("mylist").isScrolling) {
        console.log("Scroll stopped: " + item.page.getViewById("mylist).isScrolling);
        return;
    } else {
        console.log("unable to stop:" + item.page.getViewById("mylist).isScrolling);
    }
}

【问题讨论】:

  • 当我在滚动时触摸屏幕(点击事件引发)。预期结果:停止滚动实际结果是:无法停止滚动。它总是返回假。如果我是真的,那么我可以通过这种方法停止if(item.page.getViewById("mylist").isScrolling) { console.log("Scroll stopped: " + item.page.getViewById("mylist).isScrolling); return; }

标签: nativescript


【解决方案1】:

Js代码需要是:

var frame = require('ui/frame');

exports.myTapListener = function(args) {
    var page = frame.topmost().currentPage;
    if(page.getViewById("mylist").isScrolling) {
        console.log(page.getViewById("mylist").isScrolling);
    } else {
        topmost().navigate("module/a1")
    }
}

exports.myTapListener1 = function(args) {
    var page = frame.topmost().currentPage;
    if(page.getViewById("mylist").isScrolling) {
        console.log(page.getViewById("mylist).isScrolling);
    } else {
        topmost().navigate("module/a2")
    }
}
这些事件处理程序中的

args.object 不是页面对象;但产生事件的项目。所以你只需要引用 frame.topmost().currentPage

的 currentPage

【讨论】:

  • 我试图停止滚动然后我点击导航但是page.getViewById("mylist").isScrolling 在滚动时我得到了错误的响应。
猜你喜欢
  • 2014-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-11
  • 2011-04-06
  • 1970-01-01
  • 2016-02-20
  • 1970-01-01
相关资源
最近更新 更多