Receiving touch events on more then one UIView simultaneously

后端 未结 2 1271
清歌不尽
清歌不尽 2021-01-01 07:10

I have a bunch of UIViews stacked one upon the other(not nested). I want them all to react to touch, but it seems that the topmost view obscures the views benea

2条回答
  •  醉话见心
    2021-01-01 07:42

    You can check if the touch is for your topmost view. If it doesn't you can call the same method of your superview. Something like [self.superview sameMethod:sameParameter].

    Your topmost view has a method

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    

    Inside that method you are doing your logic right? Inside the method can't you check if the touch received is at your topmost view with

    UITouch *touch = [touches anyObject];
    [touch locationInView:self];

    And if it doesn't you pass it to the superView's same method using

    [self.superview touchesEnded:touches withEvent:event];
    

提交回复
热议问题