如果我理解正确,touchesEnded事件是检测到的,但不是由需要知道它的子视图。我认为这可能适用于您:
在通用文件中,将TOUCHES_ENDED_IN_SUPERVIEW定义为@“触摸在超级视图中结束”。
在含认为是烧成touchesEnded方法中,添加
[[NSNotificationCenter defaultCenter] postNotificationName: TOUCHES_ENDED_IN_SUPERVIEW object: self];
在子视图的的touchesBegan,添加
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(touchesEnded:)
name: TOUCHES_ENDED_IN_SUPERVIEW
object: self.superview];
在子视图的touchesEnded方法,使用您事件的正常逻辑,并且还添加
[[NSNotificationCenter defaultCenter] removeObserver: self name: TOUCHES_ENDED_IN_SUPERVIEW object: self.superview];
请记住在你的dealloc中放置[[NSNotificationCenter defaultCenter] removeObserver:self],以防万一可能离开页面而没有得到touchesEnded事件。
您可能希望通知将其消息发送到一个特殊的touchesEndedInSuperview方法,该方法将调用touchesEnded本身,但这取决于您是否有任何特殊的处理。
谢谢Amagrammer,我给这个一杆。这对我来说听起来很不错,但我已经把我的代码分成了暂时不涉及这个问题,我不想再次开启这些门。如果它有效,我一定会让你知道的。 – 2009-08-17 14:24:58