iOS UIButton在帧外接收触摸,但不在帧内

时间:2012-05-07 23:04:27

标签: ios cocoa-touch event-handling uikit touch-event

我有一个带有框架(4,8),(13,13)的子视图UI按钮。

触摸A位于相对于superview的位置(4,16),但是会被发送到superview,即使它位于按钮边界内。在窗口坐标中,这是(49,131)。

触摸B出现一个像素,窗口坐标为(48,131),但是会被发送到子视图按钮,即使它超出范围。视图报告UIButton中的(-1,7)位置。

触摸A

<UITouch: 0x7b2ddeb0> phase: Ended tap count: 1 
window: <DebugWindow: 0x791357f0; baseClass = UIWindow; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x791358d0>> 
view: <QueueOverlayCellView: 0x7b1ca320; frame = (2 2; 269 30); tag = 1; layer = <CALayer: 0x7b1ca3a0>> 
location in window: {49, 131} previous location in window: {49, 131} 
location in view: {4, 16} previous location in view: {4, 16}

触摸B

<UITouch: 0x7b442e90> phase: Ended tap count: 1 
window: <DebugWindow: 0x791357f0; baseClass = UIWindow; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x791358d0>>
view: <TableButton: 0x7b1cada0; baseClass = UIButton; frame = (4 8; 13 13); opaque = NO; layer = <CALayer: 0x7b1cae40>> 
location in window: {48, 130} previous location in window: {48, 130}
location in view: {-1, 7} previous location in view: {-1, 7}

superview没有实现自定义pointInside方法。

如何将超出界限的触摸转发到子视图,并将子视图范围内的触摸转发到超级视图?

1 个答案:

答案 0 :(得分:0)

不是解决方案,而是针对我自己的问题的解决方法。

这种奇怪的行为似乎发生在太小的按钮上,在这种情况下是13x13。扩展按钮大小(并使用contentInsent进行图像放置),将可触摸区域(在这种情况下将其扩展到43像素宽)增加到按钮的大约一半。