![](/img/trans.png)
[英]ADBannerNavigation white space where Ad should be when popping view controller
[英]iAdSuite bug leaves white space when ad disappears
我正在尝试在我的应用程序中合并iAdSuite标签栏视图实现,我在套件和我的应用程序中看到了同样的问题。 广告出现后,我的内容视图会正确调整大小并正确显示广告。 当广告消失后,它会留下它所在的空白区域。 但是,我已经确认我的内容视图确实调整回原来的高度,并将其缩小到原始边界。 您无法看到广告所在的部分。 我已经确保每个视图都有一个layoutIfNeeded,以及我能想到的其他所有内容都无济于事。 有什么想法吗?
编辑:我已经弄清楚问题是什么。 每次调用showBannerView:时,Apple的示例显然会将_bannerView添加到self.view但从不删除视图。 由于横幅视图在屏幕外移动,但仍然没有完全合理,但删除它确实解决了空白问题。 我的解决方案如下,但如果有人有更优雅的方式,请告诉我。
- (void)layoutAnimated:(BOOL)animated {
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect contentFrame = self.view.bounds;
contentFrame.origin = CGPointMake(0.0, 0.0);
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}
completion:^(BOOL finished) {
if (!_bannerView.bannerLoaded) {
[_bannerView removeFromSuperview];
_bannerView=nil;
}
}];
}
- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
_bannerView = bannerView;
if (![self.view.subviews containsObject:_bannerView])
[self.view addSubview:_bannerView];
[self layoutAnimated:animated];
}
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
[self layoutAnimated:animated];
}
我有同样的问题。 从hideBannerView委托方法中的超级视图中删除bannerview似乎已经解决了它。
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
[self layoutAnimated:animated];
[_bannerView removeFromSuperview];
_bannerView = nil;
}
感谢这个问题和答案,我正在用这个问题。 我改变了这个该死的代码,现在隐藏动画正常工作。 我想知道苹果为何会发布有缺陷的示例代码......
- (void)layoutAnimated:(BOOL)animated hide:(BOOL)hide
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (!hide) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
contentFrame.size.height += _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
} completion:^(BOOL finished) {
if (hide) {
[_bannerView removeFromSuperview];
_bannerView=nil;
}
}];
}
- (void)showBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
_bannerView = bannerView;
[self.view addSubview:_bannerView];
[self layoutAnimated:animated hide:NO];
}
- (void)hideBannerView:(ADBannerView *)bannerView animated:(BOOL)animated
{
[self layoutAnimated:animated hide:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.