所以我大致按照本教程介绍如何使iAd横幅不覆盖Phonegap应用程序,但不得不即兴创作,因为它并没有真正起作用。 因此,在我的mainViewController
方法webViewDidFinishLoad
中,这是我所拥有的:
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
{
adView.frame = CGRectOffset(adView.frame, 0, [[UIScreen mainScreen] bounds].size.height - 70);
adView.delegate = self;
[adView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
[theWebView addSubview:adView];
[self.view bringSubviewToFront:adView];
return [ super webViewDidFinishLoad:theWebView ];
}
adView
已正确初始化并正常运行。 破坏这一点(如我无法单击横幅)的是 viewWillAppear
中的这段代码:
- (void)viewWillAppear:(BOOL)animated
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 70;
self.webView.frame = viewBounds;
}
[super viewWillAppear:animated];
}
我添加了 70px 偏移量,以使横幅不覆盖内容。 现在,如果我删除此代码,我可以很好地单击横幅。 怎么了?
愚蠢的我。 我将子视图添加到theWebView
而不是self.view
,这使得它超出了其边界并且无法单击。