层命中测试只有当下半层被触摸时返回层 [英] layer hit test only returning layer when bottom half of layer is touched

查看:99
本文介绍了层命中测试只有当下半层被触摸时返回层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子层在层支持视图。子图层的内容设置为图像参考,是一个25x25的矩形。

当调用touchesBegan和touchesMoved方法时,对超级图层执行命中测试。命中测试方法实际上返回子层,如果它被触摸,但只有当图像的下半部分被触摸。如果图像的上半部分被触摸,它会返回上层。

I have a sublayer on a layer-backed view. The sublayer's contents are set to an Image Ref and is a 25x25 rect.
I perform a hit test on the super layer when the touchesBegan and touchesMoved methods are invoked. The hit test method does, in fact, return the sublayer if it is touched, BUT only if the bottom half of the image is touched. If the top half of the image is touched, it returns the superlayer instead.

我知道iPhone操作系统补偿用户触摸的倾向低于预期。即使我将子图层调整到更大的尺寸,50x50,它表现出相同的行为。

I do know the iPhone OS compensates for the tendancy of user touches to be lower than intended. Even if I resize the sublayer to a larger size, 50x50, it exhibits the same behavior.

任何想法?

推荐答案

感谢Kevin ...

Thanks Kevin...

我的代码与UIViews。这太麻烦,只是试图找出为什么UIView不知道什么层被触摸。我的想法的背后的全部推理是,我将有一个100多个项目在屏幕上一次,并认为图层将比UIViews处理器更容易。我有应用程序和运行,现在和100个意见是不给它任何打嗝。

I ended up just redoing my code with UIViews. It was too much trouble just trying to figure out why the UIView didn't know what layer was being touched. My whole reasoning behind the idea was that I will have a 100+ items on screen at one time, and thought Layers would be easier on the processor than UIViews. I have the app up and running now and 100 views isn't giving it any hiccups.

我对其他人的建议只是在可能的情况下使用命中测试UIViews,它使代码更简单

My suggestion to others is just stick with hit testing UIViews when possible, it makes the code much simpler

这篇关于层命中测试只有当下半层被触摸时返回层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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