2011-06-01 87 views
1

我在我的主要UIView中使用touchesBegan方法创建第二个UIView并将其添加为子视图。我想要做的是当我抬起手指时,让第二个UIView获得touchesEnded事件。我似乎无法做到这一点 - 我点击的原始UIView总是收到touchesEnded事件。如何通过touchesBegan在不同的UIView上添加touchesEnd到UIView?

编辑:我必须找到某种方式的原因为“转移”的touchesEnded是初始touchesBegan是由作为在添加新的UIView同时子视图删除一个UIView接到,所以当子视图被移除时,touchesEnded实际上会立即触发。

回答

0

我不认为你可以让新的UIView获得touchesEnded事件。您可能不得不求助于touchesEnded事件中的触摸位置,然后向父视图询问哪个子视图包含该位置。

2

哼什么,我会做的是以下几点:

- touchesEnded 
{ 
    if(yourViewIsThereAsSubView) 
    { 
    // pass on the event to the other view 
    [yourSubView touchesEnded]; 
    return; 
    } 
    // normal behaviour 
    [super touchesEnded]; 
}