如何通过touchesBegan在不同的UIView上添加touchesEnd到UIView?
问题描述:
我在我的主要UIView中使用touchesBegan
方法创建第二个UIView并将其添加为子视图。我想要做的是当我抬起手指时,让第二个UIView获得touchesEnded
事件。我似乎无法做到这一点 - 我点击的原始UIView总是收到touchesEnded
事件。如何通过touchesBegan在不同的UIView上添加touchesEnd到UIView?
编辑:我必须找到某种方式的原因为“转移”的touchesEnded
是初始touchesBegan
是由作为在添加新的UIView同时子视图删除一个UIView接到,所以当子视图被移除时,touchesEnded
实际上会立即触发。
答
我不认为你可以让新的UIView获得touchesEnded事件。您可能不得不求助于touchesEnded事件中的触摸位置,然后向父视图询问哪个子视图包含该位置。
答
哼什么,我会做的是以下几点:
- touchesEnded
{
if(yourViewIsThereAsSubView)
{
// pass on the event to the other view
[yourSubView touchesEnded];
return;
}
// normal behaviour
[super touchesEnded];
}