canDisplayBannerAds disrupting UIScrollView
In the app I’m currently working on, I have a UIScrollView with content. I just started using the new canDisplayBannerAds and noticed that the scroll view would stop scrolling after an ad appeared. The scrolling would not return if the ad went away.
Using Reveal, I found that the scroll view’s content size (height specifically) would be set to the same value as the scroll view’s frame. This has the effect of disabling scrolling. My first stab at fixing this was to disable Autoresize Subviews of the scroll view, but that didn’t work.
So I figured I would reset the content size back. I thought I’d used bannerViewDidLoadAd, but it turns out that, per https://devforums.apple.com/message/922541#922541, “the banner delegate methods are handled internally and not forwarded to your application in any way (and neither can you legitimately gain access to the used banner ad)” so I needed to find another way.
This is the suggested solution:
#pragma mark - iAD
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
if (self.displayingBannerAd )
{
// When the ad banner appears, the scrollview's content is resized
// to it's frame which disables scrolling and thus the tug to refresh
// doesn't work anymore.
CGRect screenRect = [[UIScreen mainScreen] bounds];
[scrollView setContentSize:CGSizeMake(screenRect.size.width, (scrollView.frame.size.height + 2))];
}
}