我有一个父 UIView 和一个子 UIView,我想让触摸从子视图传递到父视图,并由两个视图处理。
y--------------
| parent |
| x------ |
| |child| |
| |_____| |
|_____________|
Run Code Online (Sandbox Code Playgroud)
所以在子视图中,我覆盖:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// child touch handle
// ...
// parent touch handle
[self.nextResponder touchesBegan:touches withEvent:event];
}
Run Code Online (Sandbox Code Playgroud)
谢谢@Fogmeister。就是这样。
UITouch 现在可以传递给父级。在父母的touchesBegan,打电话
[touch locationInView:self]
Run Code Online (Sandbox Code Playgroud)
获取触摸位置。