我正在使用此代码隐藏iAd,因为Apple文档建议。但有时候它并没有隐藏iAd,即使是日志记录也暗示了if-block运行的内部代码。
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"Error loading");
if (isAdVisible == YES )
{
NSLog(@"Inside error loading");
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectMake(0, -50, 320, 50);
[UIView commitAnimations];
isAdVisible = NO;
}
}
答案 0 :(得分:0)
我使用CGRectOffset
来偏移banner.frame(它返回一个原点偏离源矩形的矩形)。然后我用一个块启动动画。以下代码在bannerView:didFailToReceiveAdWithError:
内调用,调整我UITabBarController.tabBar
的大小并隐藏它下面的AdBannerView
:
-(void) hideBanner: (UIView*) banner
{
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
// Hide the banner by sliding down while resizing the contentController.view.frame
if(banner && !banner.isHidden){
CGRect tabBarFrame = self.contentController.tabBar.frame;
[UIView animateWithDuration:0.25 animations:^{
self.contentController.tabBar.frame = CGRectOffset(tabBarFrame, 0, banner.frame.size.height);
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
} completion:^(BOOL finished) {
banner.hidden = YES;
}];
}
}