我的iAd使用UITabBarController-iAds的修改版本几乎完美地工作。我唯一的问题是广告的第一次加载我的视图被覆盖。广告在30秒后刷新后,视图会很快调整大小。
我正在使用以下代码:
- (void)layoutBanner
{
float height = 0.0;
ADBannerView *_banner = (ADBannerView *)[self.view viewWithTag:12];
CGRect bounds = [UIScreen mainScreen].bounds;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_banner.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
//When compiling against iOS 8 SDK this needs to be height, regardless of the actual device orientation
height = bounds.size.height;
CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier:_banner.currentContentSizeIdentifier];
//Get content view
UIView *_contentView = self.selectedViewController.view;
CGRect contentFrame = _contentView.frame;
CGRect bannerFrame = _banner.frame;
if (_banner.isBannerLoaded) {
if (iOS7) {
contentFrame.size.height = height - bannerSize.height;
bannerFrame.origin.y = contentFrame.size.height - self.tabBar.frame.size.height;
} else {
contentFrame.size.height = height - self.tabBar.frame.size.height - bannerSize.height;
bannerFrame.origin.y = contentFrame.size.height;
}
} else {
if (iOS7) {
contentFrame.size.height = height;
bannerFrame.origin.y = bounds.size.height;
} else {
contentFrame.size.height = height - self.tabBar.frame.size.height;
bannerFrame.origin.y = bounds.size.height;
}
}
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
_contentView.frame = contentFrame;
} completion:^(BOOL finished) {
[self.view bringSubviewToFront:_banner];
}];
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"Did load");
[self layoutBanner];
}
有什么想法吗?
答案 0 :(得分:2)
我设法通过玩动画块解决了这个问题。我移动了内容视图行并解决了问题
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
} completion:^(BOOL finished) {
_contentView.frame = contentFrame;
[self.view bringSubviewToFront:_banner];
}];
答案 1 :(得分:0)
我不是百分百肯定,但我认为问题与:
有关[self.view bringSubviewToFront:_banner];
整个动画:
[UIView animateWithDuration:0.25 animations:^{
_banner.frame = bannerFrame;
_contentView.frame = contentFrame;
} completion:^(BOOL finished) {
[self.view bringSubviewToFront:_banner];
}];
有点奇怪,因为在完成块你将横幅视图放在前面,所以我可以假设在动画开始之前 - 横幅被其他一些视图覆盖 - 帧动画的原因是什么如果覆盖了横幅视图 - 因此在动画进行过程中无法看到它?
当然这个问题仅适用于第一次运行。
答案 2 :(得分:0)
从iOs8 [[UIScreen主屏幕]界限]发生了变化..以前它总是返回肖像(其中H> W)值,不管interfaceOrientation如何,但它现在看来是尊重界面方向...... (这不是一件坏事,除非你以前的行为是理所当然的)
为什么不尝试CGRectGetMinY(CGRect aRect)..
例如。 (我从你的代码中假设横幅沿着屏幕底部,而你的TAbBar横跨顶部。(我觉得这很奇怪......)
//once you have calculated bannerFrame
contentFrame.size.height = ( CGRectGetMinY(bannerFrame) - CGRectGetMinY (contentView.frame) );
contentFrame.origin.y = CGRectGetMaxY(self.tabbar.frame);