我做了一个游戏(已经填满了屏幕),但现在我想用admob添加一个横幅。
如果我现在添加横幅,我正在使用的部分屏幕将因横幅而被阻止。如何在不覆盖游戏场景的情况下插入横幅?
PS:所有尺码都基于我的frame.size,所以我试过
frame.size.height = 0.9 * frame.size.height
但这不起作用(给出错误)
这样做的正确方法是什么?
答案 0 :(得分:0)
您不能直接修改view.frame或.bounds(并且不推荐使用它)。
要做到这一点,你必须创建一个非常新的框架:
gameView.frame = CGRectMake(CGRectGetMinX(gameView.bounds),
CGRectGetMinY(gameView.bounds),
CGRectGetWidth(gameView.bounds),
CGRectGetHeight(gameView.bounds) * 0.9f);
答案 1 :(得分:0)
CGRect contentFrame = self.view.bounds;
if (contentFrame.size.width < contentFrame.size.height) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
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;
}];
这里的内容视图是UIViewController的实例,_bannerView是GADBannerView实例。