Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Nativescript+;角度滚动视图滚动到终端侦听器_Angular_Nativescript_Angular2 Nativescript_Nativescript Angular - Fatal编程技术网

Angular Nativescript+;角度滚动视图滚动到终端侦听器

Angular Nativescript+;角度滚动视图滚动到终端侦听器,angular,nativescript,angular2-nativescript,nativescript-angular,Angular,Nativescript,Angular2 Nativescript,Nativescript Angular,当ScrollView被滚动到最底部时,是否有可用于识别的回调? 在Nativescript文档中,只提到了滚动事件,但它只提供了有关当前滚动的X或Y线的信息。不确定此事件是否对我有帮助,因为我的滚动视图高度是动态的。您仍然可以收听滚动事件,查看当前垂直偏移量是否等于滚动视图中最后一个组件的位置 大概 // Attached to layoutChange event of your container element inside scroll view onLayoutChanged(e

ScrollView
被滚动到最底部时,是否有可用于识别的回调?
在Nativescript文档中,只提到了
滚动
事件,但它只提供了有关当前滚动的X或Y线的信息。不确定此事件是否对我有帮助,因为我的
滚动视图
高度是动态的。

您仍然可以收听
滚动
事件,查看当前
垂直偏移量
是否等于
滚动视图中最后一个组件的
位置

大概

 // Attached to layoutChange event of your container element inside scroll view
 onLayoutChanged(event: EventData) {
    const containerLyt = <StackLayout>event.object,
        length = containerLyt.getChildrenCount(),
        lastItem = containerLyt.getChildAt(length - 1);

    this.lastItemY = lastItem.getLocationRelativeTo(containerLyt).y;
}

onScroll(event: EventData) {
    const scrollView = <ScrollView>event.object,
        verticalOffset = scrollView.getActualSize().height + scrollView.verticalOffset;

    if (verticalOffset >= this.lastItemY) {
        console.log("Reached end of scroll");
    }
}
//附加到滚动视图中容器元素的layoutChange事件
onLayoutChanged(事件:EventData){
const containerLyt=event.object,
长度=containerLyt.getChildrenCount(),
lastItem=containerLyt.getChildAt(长度-1);
this.lastItemY=lastItem.getLocationRelativeTo(containerLyt).y;
}
onScroll(事件:EventData){
const scrollView=event.object,
verticalOffset=scrollView.getActualSize().height+scrollView.verticalOffset;
如果(垂直偏移量>=此.lastItemY){
console.log(“到达滚动的末尾”);
}
}

通过比较ScrollView.scrollableHeight和ScrollEventData.scrollY,只需检测ScrollView的结尾,就像:

let scrollv : ScrollView = <ScrollView>this.scrollView.nativeElement;
scrollv.on(ScrollView.scrollEvent, function (args: ScrollEventData) { 
        if(scrollv.scrollableHeight === args.scrollY){
            console.log("load more items here !!! ");
        } 
 });
让scrollv:ScrollView=this.ScrollView.nativeElement;
scrollv.on(ScrollView.scrollEvent,函数(args:ScrollEventData){
if(scrollv.scrollableHeight==args.scrollY){
log(“在此加载更多项目!!!”;
} 
});

谢谢。你的回答确实帮助我找到了解决办法。我晚点再寄。尽管有趣的是getLocationRelativeTo总是返回略小于verticalOffset的值,所以它永远不会小于verticalOffset。差别总是固定的。我想知道这是否与布局中的最后一个子元素的高度如此之高,以至于最初无法在屏幕上以全高显示这一事实有关。这是一个伪代码,我没有实际测试,我已经用工作示例将答案更新为.change.nativeElement到.nativeView。优雅的解决方案