Garyo
Garyo

Reputation: 25

AdMob 6.12.0 - Prevent Scrolling (iOS)

- (void)preventGADBannerViewBounceScrolling:(GADBannerView*)bannerView {
    for (UIWebView *webView in bannerView.subviews) {
        if ([webView isKindOfClass:[UIWebView class]]) {
            webView.scrollView.scrollEnabled = NO;
            webView.scrollView.bounces = NO;
        }
    }
}

I have been using the above code to stop the AdMob banner from scrolling.

I just updated the SDK to the latest (6.12.0) and having this code and calling it with the following...

[self.view addSubview:self.adMobBannerView]; 
[self preventGADBannerViewBounceScrolling:(GADBannerView *)_adMobBannerView];

Does nothing on the latest SDK, I was wondering if anyone has had this issue and resolved it?

Also when on this subject, I have noticed some developers have made their banners so if the user clicks then it opens up in a web view within the application and has a "Done" button at the right hand corner so the user does not fully leave the application when they press on the in-app adverts, I think that is genius...

If anyone could tell me how that is done I would appreciate that greatly!

Upvotes: 2

Views: 849

Answers (2)

aleh
aleh

Reputation: 455

It looks like UIWebView is wrapped into one more view in the new SDK, so it's better to go through the whole subview tree:

- (void)walkSubviewsOfView:(UIView *)v block:(void (^)(UIView *))block {
    block(v);
    for (UIView *subview in v.subviews) {
        [self walkSubviewsOfView:subview block:block];
    }
}

- (void)disableBannerWebViewBouncing {
    [self walkSubviewsOfView:_bannerView block:^(UIView *v) {
        for (UIGestureRecognizer *r in v.gestureRecognizers) {
            if ([NSStringFromClass(r.class) isEqual:@"UIWebTouchEventsGestureRecognizer"])
                    r.enabled = NO;
        }
        if ([v isKindOfClass:[UIScrollView class]])
            ((UIScrollView *)v).bounces = NO;
    }];
}

Of course this is not a future proof solution as well, I'd prefer there would be a corresponding property in the SDK.

Upvotes: 1

Stakenborg
Stakenborg

Reputation: 2940

I went with a non-block version of aleh's answer, I found it easier to read:

- (void)removeScrollingFromView:(UIView *)view
{
    for (UIView *subview in view.subviews) {
        [self removeScrollingFromView:subview];
    }
    if ([view isKindOfClass:[UIWebView class]]) {
        ((UIWebView *)view).scrollView.scrollEnabled = NO;
        ((UIWebView *)view).scrollView.bounces = NO;
    }
}

I know I won't have any scrolling ads, but if you do, just disable bouncing and not scrolling. If you vote up my answer, please consider giving aleh a vote up too!

Upvotes: 1

Related Questions