如何检查3根手指是否放在屏幕上

发布于 2024-10-02 19:38:40 字数 1828 浏览 0 评论 0原文

对于我的应用程序,我想使用所有内置的操作可能性,例如缩放。但是,如果用户在屏幕上按 3 个手指,我想显示一个特定的 UI 元素。那么检查用户是否同时按下 3 个手指并在屏幕上彼此相邻的最佳方法是什么? (不禁用内置的操作可能性)。

我的第一个方法是在布局的顶部网格元素上注册 TouchDown 事件。在事件处理程序中我得到了联系方式。但在那里做什么呢?

只需检查联系人是否是指纹,将其存储在列表中,然后检查该列表是否已包含两个相似的联系人?

或者有更性感的解决方案吗?

谢谢!

编辑:

按照答案,我写了两种方法:

private void OnContactDown(object sender, ContactEventArgs e)
        {
            if (this.ContactsOver.Count == 3)
            {
                Console.WriteLine("3 contacts down. Check proximity");

                if (areNear(this.ContactsOver))
                {
                    Console.WriteLine("3 fingers down!");
                }
            }
        }

        private Boolean areNear(ReadOnlyContactCollection contacts)
        {
            if ( Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(1).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(1).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

它们必须重写,但它有效。并且必须调整阈值(atm 100)。

For my application I'd like to use all the built in manipulation possibilities, like e.g. zoom. But if the user presses 3 fingers on the screen I'd like to show a specific UI element. So what is the best way to check if the user has pressed 3 fingers at the same time and next to each other on the screen? (without disabling the built-in manipulation possibilties).

My first approach was to register the TouchDown event on the top Grid element of my layout. In the event handler I get the contact. But what to do there?

Just check if the contact is a fingerprint, store it in a List, and check if the list already contains two similar conacts?

Or is there a more sexy solution?

Thanks!

Edit:

Following the answer i wrote two methods:

private void OnContactDown(object sender, ContactEventArgs e)
        {
            if (this.ContactsOver.Count == 3)
            {
                Console.WriteLine("3 contacts down. Check proximity");

                if (areNear(this.ContactsOver))
                {
                    Console.WriteLine("3 fingers down!");
                }
            }
        }

        private Boolean areNear(ReadOnlyContactCollection contacts)
        {
            if ( Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(1).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(1).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(1).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).X - contacts.ElementAt(2).GetCenterPosition(this).X) < 100 &&
                 Math.Abs(contacts.ElementAt(0).GetCenterPosition(this).Y - contacts.ElementAt(2).GetCenterPosition(this).Y) < 100)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

They have to be rewritten, but it works. And the threshold (atm 100) has to be adjusted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坐在坟头思考人生 2024-10-09 19:38:40

所有表面控件上都有一个属性,其中包含其上的触点数量。该属性是 ContactsOver 或其任何变体,具体取决于您的需要,请参阅 http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

您例如,可以在 ContactDown 事件处理程序中检查该属性的 Count 值。要检查它们的距离,只需对它们执行 GetPosition 并对这些点使用基本向量数学即可。

There is a property on all surface controls that contains the number of contacts över it. The propery is ContactsOver or any variant of it depending on your need, see http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.controls.surfacecontrol_properties(v=Surface.10).aspx

You could check that propery's Count value in your ContactDown event handler for instance. To check their distance, just do a GetPosition on them and use basic vector math on the points.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文