如何确定Xamarin Forms中水龙头的位置? [英] How to determine location of a tap in Xamarin Forms?

查看:73
本文介绍了如何确定Xamarin Forms中水龙头的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin Forms中,我如何找出水龙头的位置(例如在图像中)?我的代码是:

In Xamarin Forms how do I find out the location of a tap (within an image, say)?My code is:

var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += OnTapGestureRecognizerTapped;
image.GestureRecognizers.Add(tapGestureRecognizer);
...
...
void OnTapGestureRecognizerTapped(object sender, EventArgs args)
{ ... }

args.Parameter返回null(对于iOS).我没有找到有关Parameter的任何文档.在处理程序中,我尝试将EventArgs更改为TappedEventArgs,但随后未编译.还尝试将args强制转换为TappedEventArgs,但这没有任何改变.

args.Parameter returns null (for iOS). I did not find any docs for Parameter. In the handler I tried changing EventArgs to TappedEventArgs but then did not compile. Also tried casting args to TappedEventArgs but that did not change anything.

推荐答案

经过几天寻找最简单的解决方案,我终于找到了它(实际上很遗憾,没有构建方法来获得抽头坐标...).无论如何,这就是您要寻找的东西: https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/app-fundamentals/effects/touch-tracking

After days of searching for the easiest solution, I finally found it (actually it's quite a shame that there is no build way to get the tap coordinates...). Anyway here is what you're looking for: https://docs.microsoft.com/en-gb/xamarin/xamarin-forms/app-fundamentals/effects/touch-tracking

在此处有示例:

https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/effects-touchtrackingeffect/

我已经在我的应用程序中尝试过了,您所需要的只是

I already tried it within my app and all you need is

  • TouchActionEventArgs.cs

TouchActionEventHandler.cs

TouchActionType.cs

TouchEffect.cs

添加到项目中(仅重命名名称空间),然后将 TouchEffect.cs 添加到 .Android 部分(再次重命名所有名称以与的名称相对应).您的应用).

to add to the project (only rename the namespace) and than add TouchEffect.cs to the .Android section (again rename all names to correspond with the name of your app).

然后就可以了,编码愉快;)

And there you go, happy coding ;)

这篇关于如何确定Xamarin Forms中水龙头的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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