2017-06-29 54 views
1

我有一个Ionic应用程序,头部需要根据scrollTop调整大小。我使用的是离子的滚动事件上IonScroll:Ionic 2 - 当手指离开屏幕时不会触发滚动事件

import { Scroll } from 'ionic-angular'; 

@ViewChild(Scroll) scroll: Scroll; 

... 

ionViewDidLoad() { 
    this.scroll.addScrollEventListener((ev) => { 
     console.log('scroll'); 
    }); 
} 

在iOS上,当我把我的手指在屏幕上的滚动事件是完全解雇,但是当手指离开屏幕(但滚动延续,因为惯性),事件仅在滚动停止时被触发。

当手指离开屏幕时,是否有办法收听滚动事件(或任何其他类似事件)?

我发现这个问题,这似乎是相似的,但没有任何回答:iOS scroll event not firing as often when finger is off of the screen

+0

你可以试试'touchmove'' touchstart'' touchend'事件 – Duannx

+0

我想要的是当手指没有触摸屏幕时(即当内容由于iOS上的滚动动态而仍然滚动时)听滚动,我相信'touchstart '','touchend'和'touchmove'仅在手指在屏幕上时被触发... –

回答

3

几个月前我也有类似的问题(在我的情况,我想显示/隐藏“scrollToTop”按钮当滚动到列表中时,它会在手指在屏幕上时正常工作,但如果你放开它,则不会起作用

底线是UIWebView在滚动和滚动检测方面似乎有一些限制这些问题见:https://github.com/ionic-team/ionic/issues/10630

解决方案,Ionic-Team建议ests正在使用WKWebView,因为这些问题在那里不存在。你可以试试,但我敢肯定它不会让你的情况的差异

https://github.com/ionic-team/cordova-plugin-wkwebview-engine

最后一两件事,是在NgZone运行代码:

import { NgZone } from '@angular/core'; 

export class myPage { 
    zone: NgZone; 

    constructor() { 
    this.zone = new NgZone({enableLongStackTrace: false}); 

    this.content.ionScroll.subscribe(($event) => { 
     this.zone.run(() => { 
      // console.log($event); 
     }); 
    }); 
    } 
} 
+0

我从来没有听说过WKWebView解决方案,它只是解决了我的问题。谢谢! –

相关问题