第一步導入 iAd.framework
#import "ViewController.h" #import <iAd/iAd.h> //遵守協議 @interface ViewController ()<ADBannerViewDelegate> //廣告的View @property (weak, nonatomic) IBOutlet ADBannerView *bannerView; //約束 加載完成改變 @property (weak, nonatomic) IBOutlet NSLayoutConstraint *cons; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.bannerView.delegate = self; } //加載完廣告會調用 - (void)bannerViewDidLoadAd:(ADBannerView *)banner { self.cons.constant = 8; [UIView animateWithDuration:2.0 animations:^{ [self.view layoutIfNeeded]; }]; NSLog(@"加載完畢"); } @end