How to send touch events to superview in iOS?

前端 未结 3 1513
眼角桃花
眼角桃花 2020-12-30 17:56

I am doing an iPad app. How do I send touch events to its superview?

I am adding a view which is always some other activity. On that I am adding scrollview to h

3条回答
  •  执笔经年
    2020-12-30 18:30

    Set the view's userInteractionEnabled property to NO. This lets all touches through to the view behind it.

    You can set it in the interface builder/storyboards in the attributes inspector, or in code:

    yourView.userInteractionEnabled = NO;
    

    For when you have a transparent view with a button in it:

    Make a subclass of that view and override the pointInside method. The way I do it, is to give the button's frame to the subclass as a property, to check for in the pointInside method:

    - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
        BOOL pointInside = NO;
        // Check if the touch is in the button's frame
        if (CGRectContainsPoint(_buttonFrame, point)) pointInside = YES;
    
        return pointInside;
    }
    

    Hope it helps!

提交回复
热议问题