2015-01-03 65 views
1

我已經搜索並搜索了該代碼,並嘗試將廣告橫幅移動到屏幕頂部進行大量試驗和錯誤。這已經一個星期了,沒有進展。如果有人能幫我解決這個問題,我會很高興。這是基於關閉的代碼是君子的偉大教程: http://codewithchris.com/iad-tutorial/似乎無法通過此代碼將iAd橫幅移動到屏幕頂部

下面的代碼:

@interface ViewController() 
{ 
BOOL _bannerIsVisible; 
ADBannerView *_adBanner; 
} 
@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)]; 
_adBanner.delegate = self; 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (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; 
    } 
} 

@end 

回答

0

改變這一行:

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)]; 

要這樣:

_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, -50, 320, 50)]; 

(其中-50是廣告橫幅的高度)。在您安裝之前g使用self.view.frame.size.height將廣告橫幅的框架放到屏幕的底部,而現在-50將框架移動到屏幕上方。

此外,不要忘記你需要將CGRectOffsets的y座標反轉(從第一個中移除( - )並將其添加到第二個座標中),因爲此刻你擁有的座標是在屏幕的底部。

希望這會有所幫助!