是否可以通过编程方式在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 backAndroid:
对于我的特殊情况,我还需要禁用滚动视图的滚动,但是将子视图拖放到内部.在子视图开始拖动(平移)事件时,我们可以通过以下方式防止滚动视图中的触摸事件被拦截:
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滚动?
发布评论