当我按下按钮时,我无法找到正确的解决方案来隐藏我的iAd视图。 我喜欢这样的iAd视图:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
它完美无缺。但是,如果我不想展示我的iAd视图,我将如何隐藏它?
我在这里寻找答案,但没有直接答案。
答案 0 :(得分:0)
如果用户没有互联网连接,则横幅将为空白。当互联网连接不可用时,苹果需要隐藏横幅。
考虑一下你是这样创造的,
- (void)createAdBannerView {
Class classAdBannerView = NSClassFromString(@"ADBannerView");
if (classAdBannerView != nil) {
self.adBannerView = [[[classAdBannerView alloc]
initWithFrame:CGRectZero] autorelease];
[_adBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:
ADBannerContentSizeIdentifier320x50,
ADBannerContentSizeIdentifier480x32, nil]];
if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier480x32];
} else {
[_adBannerView setCurrentContentSizeIdentifier:
ADBannerContentSizeIdentifier320x50];
}
[_adBannerView setFrame:CGRectOffset([_adBannerView frame], 0,
-[self getBannerHeight])];
[_adBannerView setDelegate:self];
[self.view addSubview:_adBannerView];
}
}
调用[self.adBannerView removeFromSuperview];什么时候和你需要隐藏。
答案 1 :(得分:0)
@ Matiass21,在这里写下面的代码_bannerIsVisible是bool值而_adBanner是ADBannerView对象。
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
// If banner isn't part of view hierarchy, add it
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"Failed to retrieve ad");
if (_bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}