0
votes

I'm using YouTube iOS Player Helper View and the player itself works wonderfully. However, I want the user to be able to tap on the video and have it start playing. I tried adding a UITagGestureRecognizer to the YTPlayerView, but it didn't register any of my taps.

I added a UIButton to my view and connected it to my IBAction that tells the YTPlayerView to play and that worked fine. However, I want it to appear to the user as if they've tapped the video itself. So, I resized my UIButton to be the same size as the YTPlayerView and put the UIButton on top of the YTPlayerView.

Taps on the UIButton no longer work.... almost. Any taps to the left, right, or bottom of the YTPlayerView don't work. Taps above the YTPlayerView still go through. So, if I shift my UIButton 10 pixels up, I can tap just on the 10 pixel strip and my IBAction will get called. If I move the UIButton 10 (or 30) pixels to the left, right, or bottom, none of the taps make it through to my IBAction.

In the image below, my UIButton has a green background with transparency so that you can see what's behind it. (I have tested this with it fully opaque and it behaves the same way, the transparency is not the issue.) If I tap in the green area inside the red box (i.e. above the YTPlayerView), then my IBAction is called as expected. If I tap inside the green area outside of the red box (i.e. left, right, or below the YTPlayerView), then I never received my IBAction.

This whole view is enclosed in a UIScrollView. I tried adding a UITapGestureRecognizer to self.view and when I try tapping the YTPlayerView, that tap is delivered to me as if it hits the UIScrollView instead of the YTPlayerView.

img

1

1 Answers

0
votes

Ignore touches to scrollview or forward touches from scroll view to the button

Add gesture to the playerview

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{

    if (someScrollView.superview != nil) {
        if ([touch.view isKindOfClass:[UIButton class]])
            {
            return YES; // handle the touch
            }
    }
    return NO; // ignore the touch

}