Nativescript:如何以编程方式禁用/启用ScrollView滚动?

编程入门 行业动态 更新时间:2024-10-25 05:28:23
本文介绍了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滚动?

本文发布于:2023-11-11 17:59:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   Nativescript   ScrollView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!