在我的应用程序中添加 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");
}
最后有同样的问题。
任何想法?
谢谢。