在我的应用中添加IAD横幅,但是当横幅为空(白色)横幅不会被隐藏时,我尝试了两种代码,一个是:
在我的.h
#import <iAd/iAd.h>
@interface HomeViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *homeBanner;
}
//----------------------------------iAd BANNER-------------------------//
@property (nonatomic, assign) BOOL bannerIsVisible;
@property (nonatomic, strong) IBOutlet ADBannerView *homeBanner;
@end
在类.m
@synthesize homeBanner, bannerIsVisible;
//------------iAd Banner---------------------------------------//
- (void)bannerViewDidload:(ADBannerView *)abanner {
if (!self.bannerIsVisible){
[UIView beginAnimations:@"animationAdBannerOn" context:NULL];
homeBanner.frame = CGRectOffset(homeBanner.frame, 0.0, 50.0);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)aBanner {
if (!self.bannerIsVisible){
[UIView beginAnimations:@"animationAdBannerOff" context:NULL];
homeBanner.frame = CGRectOffset(homeBanner.frame, 0.0, -320.0);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
使用此代码,如果横幅为白色,请继续显示。
尝试第二个代码:
在我的.h
#import <iAd/iAd.h>
@interface HomeViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *homeBanner;
}
//----------------------------------iAd BANNER-------------------------//
@property (nonatomic, strong) IBOutlet ADBannerView *homeBanner;
@end
和.m
- (void)viewDidLoad {
[super viewDidLoad];
[homeBanner setHidden:YES];
}
- (void)bannerViewDidload:(ADBannerView *)banner {
[homeBanner setHidden:NO];
NSLog(@"Showing");
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[homeBanner setHidden:YES];
NSLog(@"Hidden");
}
最终有相同的问题。
有什么想法吗?
谢谢。
您是否为BannerView设置了代表?
在您的ViewDidload中尝试一下 -
[homeBanner setDelegate:self];