SwiftUI:两指滑动(滚动)手势 [英] SwiftUI: Two-finger swipe ( scroll ) gesture

查看:81
本文介绍了SwiftUI:两指滑动(滚动)手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对两指滑动(滚动)手势感兴趣.

I'm interested in 2-finger swipe ( scroll ) gesture.

不是两指拖动,而是两指滑动(不按).就像在Safari中用于上下滚动一样.

Not two-finger drag, but 2-finger swipe (without press). Like used in Safari to scroll up and down.

如我所见,没有任何基本手势可用于此目的:TapGesture-不是;LongPressGesture-不;DragGesture-不;放大手势-不;RotationGesture-不;

As I see noone of basic gestures will work for this: TapGesture - is not; LongPressGesture - not; DragGesture - not; MagnificationGesture - not; RotationGesture - not;

有人对如何做到这一点有想法吗?

Have anyone some ideas how to do this?

我至少需要看一下方向.

I need at least direction to look at.

  • 这是MacOS项目
  • 顺便说一句,我无法在项目中使用UI类,因此无法将项目重新制作为目录

推荐答案

Edit: Correcting my answer cover Mac OS

上下滚动是一个 NSPanGestureRecognizer .它具有 numberOfTouchesRequired 属性,可让您根据需要使它响应2个手指.

Correcting my answer cover Mac OS

Scrolling up and down is a NSPanGestureRecognizer. That has a numberOfTouchesRequired property that lets you make it respond to 2 fingers if desired.

Mac OS没有滑动手势识别器.

Mac OS does not have a swipe gesture recognizer.

标准的 UISwipeGestureRecognizer 完全可以满足您的需求.只需将 numberOfTouchesRequired 设置为2.

The standard UISwipeGestureRecognizer does exactly what you want. Just set numberOfTouchesRequired to 2.

...虽然我不确定移动Safari是否使用滑动手势.可能是带有特定编码的2指拖动.

...Although I'm not sure mobile Safari uses swipe gestures. It might be a 2-finger drag with some special coding.

这篇关于SwiftUI:两指滑动(滚动)手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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