UIScrollView doesn't scroll when touching GADB

2019-03-16 04:12发布

I have a project that uses the Google AdMob Ads SDK. I'm trying to show a few ads on the homepage along with some other buttons, some of which are below the screen.

I've used a UIScrollView and added a few GADBannerViews from DFP inside as well the buttons. The ads load just fine and I can click on the ads and buttons with no problem.

The problem is when I try to scroll the scroll view. If I start touching on the ad view, the scroll view will not scroll. If I start touching anywhere else, like a button or a blank space, the scroll view scrolls properly. It seems that the ad is somehow taking control of the touch events.

I've tried all sorts of fixes such as creating a transparent UIView above the ads, which didn't work because the taps would not register.

I've tried looping through the subviews of the GADBannerView but all the subviews' classes seem proprietary to AdMob or inaccessible. (GADWebView, _UIWebViewScrollView)

I even tried adding the ad to a UITableView to see if it would scroll there, but it did not work either.

My view controller class is quite large so if you need me to post some code, I can create a sample app to demonstrate the problem. A workaround for now is to create UIWebViews with the HTML ad code inside instead of using the GADBannerView. I've tested this and it works, but I really don't want to lose the functionality of the native method.

Is there any way to scroll a UIScrollView if you start touching on the GADBannerView and allow the ad to remain clickable?

Thanks!

8条回答
做个烂人
2楼-- · 2019-03-16 04:55

I solved this by digging down into the GADBannerView and setting the delegate for its web browser view gestures to my own view and then just returning YES for all simultaneous gesture handling:

id webBrowserView = [[[[[[adView subviews] firstObject] subviews] firstObject] subviews] firstObject];

for (UIGestureRecognizer *gestureRecognizer in [webBrowserView gestureRecognizers])
{
    [gestureRecognizer setDelegate:self];
}

Then just return yes in the following delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
查看更多
走好不送
3楼-- · 2019-03-16 04:57

For DFP you can use a DFPSwipeableBannerView instead of a DFPBannerView. Not sure how the orignal GADBanner works tho, but this should be the same. Works in UITableView.

查看更多
登录 后发表回答