Nativescript:如何以编程方式禁用/启用ScrollView滚动? [英] Nativescript: how to programmatically disable / enable ScrollView scrolling?

查看:76
本文介绍了Nativescript:如何以编程方式禁用/启用ScrollView滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式在NativeScript中禁用/启用ScrollView滚动?

Is there a way to programatically disable/enable ScrollView scrolling in NativeScript?

推荐答案

好的,我发现了如何做到这一点.在iOS上实际上非常简单:

Ok, I found how to do that. It's actually pretty easy on iOS:

var scrollView = page.getViewById('YOUR_VIEW_ID')
scrollView.ios.scrollEnabled = false // to disable
scrollView.ios.scrollEnabled = true  // to enable back

Android:

对于我的特殊情况,我还需要禁用滚动视图的滚动,但是将子视图拖放到内部.在子视图开始拖动(平移)事件时,我们可以通过以下方式防止滚动视图中的触摸事件被拦截:

Also for my particular case, where I need to disable scrolling of the Scroll View, but drag and drop child views inside. On subview start dragging (panning) event we prevent touch events interception in our Scroll View by:

scrollView._nativeView.requestDisallowInterceptTouchEvent(true)

并通过以下方式在停止拖动(平移)子视图事件时再次启用它们:

And enable them again on stop dragging (panning) subview event by:

scrollView._nativeView.requestDisallowInterceptTouchEvent(false)

如果您还有其他情况,并且只想禁用滚动视图滚动,则可以使用以下方式(对于Android):

If you have another case and just want to disable Scroll View scrolling you can use something like this (for Android):

scrollView._nativeView.setOnTouchListener(new android.view.View.OnTouchListener({
   onTouch: function (view, motionEvent) {
       console.log("DISABLED. onTouch event: Got    motionEvent.getAction() " + motionEvent.getAction() + ".");
       return true;
    }
}))

这篇关于Nativescript:如何以编程方式禁用/启用ScrollView滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆