xcode 4.3 - 故事板 - iAd继续前进 [英] xcode 4.3 - storyboard - iAd keeps moving

查看:140
本文介绍了xcode 4.3 - 故事板 - iAd继续前进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将iAd添加到我的iphone应用程序中,以便位于我的应用程序顶部。最初我把它放在x = 0和y = -50,以便它来自屏幕。我在我的.m中使用以下代码:

I have added iAd to my iphone app to be at the top of my app. originally I place it at x=0 and y=-50 so that it comes from off the screen. I use the following code for it in my .m :

    - (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.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];
        self.bannerIsVisible = NO;
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
    if (!self.bannerIsVisible)
    {
        [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];
        self.bannerIsVisible = YES;
    }
}

当我的应用启动iAd显示在顶部时没有任何问题。但是当我打开另一个应用程序并回到它(没有杀死它以便我的应用程序在后台运行)时,横幅向下移动另外50个像素

When my app launch iAd get displayed at the top without any problem. but when I open another app and come back to it (without killing it so my app is running in the background) the banner moves another 50 pixel down

任何想法?

推荐答案

在两种情况下,您都要将 50.0px 添加到 banner.frame.origin.y

You are adding 50.0px to banner.frame.origin.y in both cases.

无论如何:即使你在中减去 50.px didFailToReceiveAdWithError: b
可能会发生 didFailToReceiveAdWithError:会在
行中被多次调用,而您的代码可能会将横幅移到更高和更高的位置( -50.0,-100.0,-150.0 ...)。

Anyway: even if you'd be substracting 50.px in didFailToReceiveAdWithError: it could happen that didFailToReceiveAdWithError: would get called multiple times in a row and your code could move the banner higher and higher up (-50.0,-100.0,-150.0...).

因此最好对隐藏的&硬盘进行硬编码。可见位置而不是计算它。

So it's better to hardcode the hidden & visible positions instead of calculating it.

试试这个:

- (void)bannerView:(ADBannerView *)abanner didFailToReceiveAdWithError:(NSError *)error
{
    if (self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOff" context:NULL];
        banner.frame = CGRectMake(0.0,-50.0,banner.frame.size.width,banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = NO;
    }
}

- (void)bannerViewDidLoadAd:(ADBannerView *)abanner
{
    if (!self.bannerIsVisible)
    {
        [UIView beginAnimations:@"animateAdBannerOn" context:NULL];
        banner.frame = CGRectMake(0.0,0.0,banner.frame.size.width,banner.frame.size.height);
        [UIView commitAnimations];
        self.bannerIsVisible = YES;
    }
}

这篇关于xcode 4.3 - 故事板 - iAd继续前进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆