获取自定义UIView以响应两指触控板的滚动手势(或鼠标滚轮) [英] Getting a custom UIView to respond to a two finger trackpad scroll gesture (or mouse scroll wheel)

查看:279
本文介绍了获取自定义UIView以响应两指触控板的滚动手势(或鼠标滚轮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPad应用程序(C#)和一个自定义UIView,该UIView允许通过触摸和Apple Pencil手写笔触摸进行输入.我正在尝试集成对触控板/鼠标间接支持(如Apple所说的光标或指针").

I have an iPad app (in C#) with a custom UIView that allows input via touch and Apple Pencil stylus touches. I am trying to integrate support for trackpad/mouse indirect (cursor, or "pointer" as Apple calls it).

我使用HoverGestureRecognizer使悬停工作.我使用正常的触摸Began/Moved/Ended/Cancelled事件进行了右键单击和控制单击,并检查.type == .indirectPointer,然后检查是否设置了event.ModifierFlags中的控制键修饰符,或者是否设置了event.ButtonMask ==次要.

I got hover working using HoverGestureRecognizer. I got right-click and control-click working using normal touch Began/Moved/Ended/Cancelled events and checking for .type == .indirectPointer and then checking if the control key modifier in event.ModifierFlags is set, or if event.ButtonMask == secondary.

我花了很多时间在Apple Developer网站上搜索文档,从这里开始并扩展:

I have spent a lot of time searching through the documentation on the Apple Developer website, starting here and branching out:

当发生两指触控板滚动(或鼠标滚轮滚动)时,我无法以某种方式找到系统在我的代码中调用的API. (在另一个视图上是滚动视图,当我进行两指滚动时,我可以获取scrollview的滚动事件,因为这是iPadOS 13.4+内置的滚动视图,但是我的自定义视图不是滚动视图,它里面有一些可滚动区域.)

Somehow I cannot find the API that the system calls in my code when a two-finger trackpad scroll (or mouse scrollwheel scroll) occurs. (On another view that is a scrollview, I can get the scrollview's scroll event when I do a two-finger scroll, since this is built-in to iPadOS 13.4+ for scroll views, but my custom view is not a scroll view, it just has some scrollable areas inside of it.)

我尝试过的事情:

  • UISwipeGestureRecognizer.两指触控板滚动手势什么也没有.
  • UIPanGestureRecognizer.没事.
  • 子类化UIScrollView并添加一个UIScrollViewDelegate,只是看它是否可以工作...什么都没有.
  • 将GestureRecognizer子类化并添加,然后覆盖ShouldReceive(UIEvent evt),但是从未调用过.

iPadOS 13.4+将触控板的两指滚动手势转换为什么?我可以将其作为某种事件吗??文档上面已链接是非常令人失望的准系统,但它提到了UIEvent.EventType.scroll,但没有提到系统将如何,何时或何地使用该类型的事件调用我的任何方法.真是气死我了.他们应该更清楚地说明这一点.

What does iPadOS 13.4+ convert the trackpad two-finger scroll gesture into? Can I get this as some sort of event? The documentation linked above is pretty disappointingly barebones, but it mentions UIEvent.EventType.scroll but not how or when or where the system will call any of my methods with an event of that type. Pretty infuriating. They should just spell this out more clearly.

欢迎使用Swift或C#进行回答.

Answers in Swift or C# are welcomed.

推荐答案

好吧,奇怪的是我以为我尝试了PanGestureRecognizer,但是我一定把它设置错了.苹果公司的示例代码项目将指针交互功能集成到iPad App 中,答案(C#代码):

OK, strangely I thought I tried PanGestureRecognizer, but I must have set it up wrong. The example code project by Apple, Integrating Pointer Interactions into Your iPad App had the answer (C# code):

        panRecognizer = new UIPanGestureRecognizer(() => {
            Console.WriteLine("panned -- " + panRecognizer.VelocityInView(this));
        });
        panRecognizer.AllowedScrollTypesMask = UIScrollTypeMask.Continuous;
        AddGestureRecognizer(panRecognizer);

很高兴我知道了!

这篇关于获取自定义UIView以响应两指触控板的滚动手势(或鼠标滚轮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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