2011-12-18 148 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):