0

我是 iOS 新手,我试图在顶部放置横幅广告,但它不起作用。我知道这是一个不好的问题,但老实说我不知道​​,所以我需要一些帮助。任何帮助是极大的赞赏。

.h 文件

#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
@interface withadViewController : UIViewController <ADBannerViewDelegate> {
ADBannerView *adView;
BOOL bannerIsVisible;
IBOutlet ADBannerView *banner1;
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
IBOutlet UILabel *label1;
}
@property (nonatomic, assign) BOOL bannerIsVisible;
-(IBAction)calculate;
-(IBAction)clear;
@end

和我的 .m 文件

@synthesize bannerIsVisible;
-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if(!self.bannerIsVisible)
{
    [UIView beginAnimations:@"animateBannerOn" context:NULL];
    // banner is invisible now and moved out of the screen on 50px
    banner.frame = CGRectOffset(banner.frame, 320, 50);
    [UIView commitAnimations];
    self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{ [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
    // banner is visible and we move it out of the screen, due to connection issue
    banner.frame = CGRectOffset(banner.frame, 0, -320);
    [UIView commitAnimations];
    self.bannerIsVisible = NO;
}
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:         -(BOOL)willLeave
{
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction)
{
    // stop all interactive processes in the app
    // [video pause];
    // [audio pause];
}
return shouldExecuteAction;
- (void)viewDidLoad {
[super viewDidLoad];
adView = [[ADBannerView alloc]initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
adView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];    
@end
4

0 回答 0