2011-12-18 153 views
0

我一直在尋找各種教程和代碼片段,嘗試實施iAd。我已經取得了一定程度的成功,但我需要自定義,我似乎無法弄清楚我需要做什麼來完成我的更改,任何人都可以提供幫助嗎?更改iAd的位置和位置

- (void)viewDidLoad 
{ 
adView = [[ADBannerView alloc] initWithFrame:CGRectZero]; 
adView.frame = CGRectOffset(adView.frame, 0, -50); 
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]; 
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; 
[self.view addSubview:adView]; 
adView.delegate = self; 
self.bannerIsVisible = NO; 
[super viewDidLoad]; 

// Do any additional setup after loading the view from its nib. 
} 

- (void)bannerViewDidLoadAd:(ADBannerView *)banner 
{ 
if (!self.bannerIsVisible) 
{ 

    [UIView beginAnimations:@"animateAdBannerOn" context:NULL]; 
    // banner is invisible now and moved out of the screen on 50 px 
    banner.frame = CGRectOffset(banner.frame, 0, 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, -50); 
    [UIView commitAnimations]; 
    self.bannerIsVisible = NO; 
} 
} 

就目前來看,橫幅被加載在UIWebView的頂部。首先,我喜歡它的底部,其次,廣告與WebView內容重疊,有什麼方法可以在廣告加載或消失時推送WebView?

我很感激任何幫助,這是駕駛彎道!

謝謝。

回答

2

將adview.frame.origin.y設置爲您想要的最低點,當您想要時。例如,我的iad是在應用程序委託中設置的,然後在我想要的視圖控制器中,在viewwillapear中,我使用adview.frame.origin.x = 0; adview.frame.origin.y = 420; [SharediAdView setframe:adview.frame];

差異設置取決於iPhone 3.5英寸/ 4英寸,當前視圖控制器中的空間,&方向。

如果你寧願一切移動向上/向下,並且不想與定製解決方案一塌糊塗,我想嘗試這個東西:https://github.com/chrisjp/CJPAdController

0
adView.frame = CGRectMake(0.0, 375.0, iAdView.frame.size.width, iAdView.frame.size.height); 

使用此代碼,而不是

adView.frame = CGRectOffset(adView.frame, 0, -50); 
banner.frame = CGRectOffset(banner.frame, 0, 50); 
banner.frame = CGRectOffset(banner.frame, 0, -50); 

並根據你想要的更改廣告位置(375.0):