【问题标题】:Cannot seem to move iAd banner to the top of the screen with this code似乎无法使用此代码将 iAd 横幅移动到屏幕顶部
【发布时间】:2015-01-03 21:03:52
【问题描述】:

我已经搜索和搜索,并在此代码上进行了大量试验和错误,试图将广告横幅移动到屏幕顶部。已经一个星期了,一点进展都没有。如果有人可以帮助我解决这个问题,我会很高兴。这是基于的代码是由绅士的伟大教程: http://codewithchris.com/iad-tutorial/

代码如下:

@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

【问题讨论】:

    标签: sprite-kit iad adbannerview banner-ads


    【解决方案1】:

    改变这一行:

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

    到这里:

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

    (其中 -50 是广告横幅的高度。)在您使用 self.view.frame.size.height 将广告横幅的框架设置到屏幕底部之前,而现在 -50 移动框架就在屏幕上方。

    另外,不要忘记您需要反转 CGRectOffsets 的 y 坐标(从第一个删除 (-) 并将其添加到第二个),因为您目前拥有的那些假设框架位于屏幕底部。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多