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!
I ran into the same issue, but decided on a simpler solution. I found that just disabling the ad's web view bounce back allowed the parent scrollview to scroll properly when the ad was touched. Since the ad is the same size as the webview, the only thing the gestureRecognizer was doing was showing the bounce back behavior. Just had to turn that off and left the current gestureRecognizer in place.
This issue can be resolved by subclassing UIScrollView, conforming to the the UIGestureRecognizerDelegate protocol, and returning YES from
You shouldn't need to set the delegate; UIScrollView is already set as the delegate of it's gesture recognizers by default.
The problem is a conflict between the gesture recognizer in the UIWebView used by GADBannerView and a custom recognizer in GADBAnnerView. Without subclassing UIScrollView and changing the gesture recognizer delegate, you can remove this gesture recognizer and set your object as delegate for custom recognizer with this:
Then you should implement the simultaneous gesture recognizer delegate to allow simultaneously recognise:
I had to combine two of the answers above:
Where bannerView_ is a GADBannerView
I ran into this issue when trying to add a DFPBannerView as a subview of the contentView of a custom cell in a table view.
For some reason, connecting an IBOutlet defined in my custom cell class to a view in the cell in my storyboard caused the scrolling to start working. The view outlet wasn't even being used, and was completely separate from the banner view - even removing it from its superview allowed the scrolling behaviour to work. Just having an outlet defined and connected to something did the trick.
I wish I could explain why this works, but it remains an iOS mystery.
Unfortunately there is not a not a way to override the scrolling gesture but retain the touch gesture for the ad. The GADBannerView itself needs to control all of the gestures on itself. There is also no way to programmatically send a click to the GADBannerView either, so you can't override the touch behavior either.
I would recommend using ads that are much smaller than your UIScrollView, so you don't have to worry too much about scrolling over an ad.