- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
如果我有一个 UIImageView 并且想知道用户是否点击了图像。在 touchesBegan 中,我执行以下操作但总是以第一个条件结束。窗口处于纵向模式,图像位于底部。我可以点击窗口的右上角,仍然进入第一种情况,这似乎很不正确。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:touch.view];
if(CGRectContainsPoint(myimage.frame, location) == 0){
//always end up here
}
else
{ //user didn't tap inside image}
值是:
location: x=303,y=102
frame: origin=(x=210,y=394) size=(width=90, height=15)
有什么建议吗?
最佳答案
首先,您要接触:
UITouch *touch = [[event allTouches] anyObject];
接下来,您要检查相对于 ImageView 的 locationInView。
CGPoint location = [touch locationInView:self]; // or possibly myimage instead of self.
接下来,CGRectContainsPoint 返回一个 bool 值,因此将它与 0 进行比较是非常奇怪的。应该是:
if ( CGRectContainsPoint( myimage.frame, location ) ) {
// inside
} else {
// outside
}
但是,如果 self 不是 myimage,那么 myimage View 可能会代替您进行触摸 - 从您的问题中不清楚 self 是什么对象,它不是所讨论的 UIImageView 的子类。
关于objective-c - 点不在 Rect 但 CGRectContainsPoint 说是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/979620/
好的,所以我有一个自定义的 rect 函数。自定义rect如下: typedef struct tagRECTEx{ // long left; // long top; // long right;
我在 Rectangles 上找到了这个很棒的数学运算文件: https://gist.github.com/Noitidart/90ea1ebd30156df9ef530c6a9a1b6ea7 及其
在我的 onDraw 中,我拥有构建整个 View 所需的所有代码,但我如何检测我是否只想执行部分重绘。我想应该通过调用 canvas.invalidate(Rect rect); 来触发部分重绘。正
我对以下游戏 map 有疑问: 我想把所有的陆地区域(黄色附近)保存在一个数组中,这样计算机以后就知道用户的点击是在水面上(鼠标指针的x/y坐标不在数组中)还是在国内(x/y 坐标光标不在数组中)。我
我尝试制作一个简单的可视化列,其中矩形的高度由比例确定: var heightScale = d3.scaleLinear() .domain([150,2500]) .range([
我在 WPF 中有一个小项目,我需要在其中交换 UIElement。类似于 iGoogle 的功能。 由于我发不了图片(信誉不够)我会用文字说明。我有一个这样定义的 3x3 网格: 0 1
这个问题已经有答案了: How do I detect collision in pygame? (5 个回答) 已关闭 6 个月前。 问候, 我在 pygame 中从事的项目似乎遇到了一些麻烦。对于
我正在使用: check = pygame.image.load("check.png") checkrect = check.get_rect() checkrect = checkrect.mov
我试图让我的玩家 rect 在侧面和底部与我的敌人 rect 碰撞,因此玩家 rect 不会抛出敌人的 rect 但我不知道为什么它一直将我传送到它根本不起作用 VIDEo platform.rec
这个问题已经有答案了: How do I get the snake to grow and chain the movement of the snake's body? (1 个回答) 已关闭 3
API 是否应该提供 Rect::contains(Point) 或 Point::is_inside(Rect) 或两者? 或 Math::contains(Point, Rect) 因为它是对称的
我在我的项目中使用 Konva.js,我特别需要在使用 Konva.Rect() 类定义的可拖动矩形内定义文本。有没有一种方法可以在不使用单独的 Konva.Text 的情况下实现这一点() 或 Ko
'annot' CGPDFDictionary 'Rect' 如何转换为 objective-c Rect: 最佳答案 Adobes PDF Spec状态: Rectangles are used t
我正在尝试在 UIView 中绘制一个字符串。 class ViewController: UIViewController { override func viewDidLoad() { s
我正在使用 D3 制作图表。我希望用户能够通过调整单列水平柱形图上堆叠条形的大小来输入他们的选择。 条形堆叠在一起,每个条形都有 .call(drag) 事件监听器。 此拖动事件返回错误。 var d
我刚刚在官方文档中浏览了 pygame 的 .rect 方法。 我们有2个案例, pygame.rect.move(arg1,arg2) 用于在屏幕上移动 .rect 对象 和 pygame.rect
所以我尝试使用实例为我的游戏进行碰撞检测。代码如下: class Paddle: def __init__(self, x, y, width, height, rect): self.x =
我是否正确使用了drawPixmap()? 本质上,我的目标是拍摄一张图 block 图像,然后用自定义图 block 图像替换单个图 block 。 我能够将两个图像都加载到屏幕上,但是当我调用 d
这个想法很简单:我有一个 SVG 路径和一个 Rect,我需要让路径穿过矩形,由此产生的“洞”应该是透明的。 这是 jsfiddle,其中包含一份它现在的样子: https://jsfiddle.ne
很抱歉问了一个菜鸟问题,但是有人能告诉我这两者之间的区别吗 cv:: Rect rect; int width = rect.width; int height = rect.height; 还有这个
我是一名优秀的程序员,十分优秀!