更改iAd位置和位置

时间:2011-12-18 14:56:07

标签: objective-c ios cocoa-touch iad ios5

我一直在研究各种教程和代码片段,尝试实现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 个答案:

答案 0 :(得分:2)

将adview.frame.origin.y设置为您想要的最低端, 时需要它。例如,我的iad是在app delegate中设置的,然后在我想要的视图控制器中,在viewwillapear中,我使用adview.frame.origin.x = 0; adview.frame.origin.y = 420; [SharediAdView setframe:adview.frame];

diff设置取决于iphone 3.5inch / 4inch,当前视图控制器中的空间,&取向。

如果您宁愿向上/向下移动所有内容,并且不想使用量身定制的解决方案,我会尝试这些内容:https://github.com/chrisjp/CJPAdController

答案 1 :(得分: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):)