如何确定iPad用户是否在不规则形状的图像内轻拍? [英] How to determine if iPad user taps within an irregular shaped image?

查看:147
本文介绍了如何确定iPad用户是否在不规则形状的图像内轻拍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个 UITapGestureRecognizer 连接到一个包含我想要在iPad屏幕上显示的图像的UIImageView,并且能够消耗用户的点击量。但是,我的图像是桌子上的一只手的图像,我想知道用户是在手上还是在图像的桌面部分上进行了轻敲。我可以用 CGPoint tapLocation = [识别器locationInView:self.view]; 得到用户点击的x,y坐标,但是我不知道如何映射CGPoint指的是包含手的图像区域与包含表格的区域。到目前为止,我读过的所有内容都涉及确定CGPoint是否位于特定的矩形区域,但如果需要确定CGPoint是否位于更不规则形状的边界内,该怎么办?这甚至有可能吗?任何建议,或只是指出我在正确的方向将是一个很大的帮助。感谢!

/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/pointInside:withEvent:rel =nofollow noreferrer> pointInside:withEvent:以编程方式定义点击区域。

详细说明一下,您只需要考虑一点,然后通过一系列if语句来评估它是否落在您之后的区域。如果是,则返回TRUE。如果不是,则返回FALSE。如果这与这篇文章,那么你可以使用一个循环条件来比较点到你的圆心的距离毕达哥拉斯定理


I've hooked up a UITapGestureRecognizer to a UIImageView containing the image I'd like to display on an iPad screen and am able to consume the user taps just fine. However, my image is that of a hand on a table and I'd like to know if the user has tapped on the hand or on the table part of the image. I can get the x,y coordinates of the user tap with CGPoint tapLocation = [recognizer locationInView:self.view]; but I'm at a loss for how to map that CGPoint to, say, the region of the image that contains the hand vs. the region that contains the table. Everything I've read so far deals with determining if a CGPoint is in a particular rectangular area, but what if you need to determine if that CGPoint is located in the boundaries of a more irregular shape? Is that even possible? Any suggestions or just pointing me in the right direction would be a big help. Thanks!

解决方案

You could use pointInside:withEvent: to define the hit area programmatically.

To elaborate, you just take the point and evaluate to see if it falls in the area you're after with a series of if statements. If it does, return TRUE. If it doesn't, return FALSE. If this is related to this post, then you could use a circular conditional to compare the distance of the point to the center of your circle using Pythagorean Theorem.

这篇关于如何确定iPad用户是否在不规则形状的图像内轻拍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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