Sprite kit 似乎无法使用此代码将iAd横幅移动到屏幕顶部

Sprite kit 似乎无法使用此代码将iAd横幅移动到屏幕顶部,sprite-kit,iad,adbannerview,banner-ads,Sprite Kit,Iad,Adbannerview,Banner Ads,我搜索了又搜索,并且在这段代码上做了很多尝试和错误,试图将广告横幅移动到屏幕顶部。已经一个星期没有进展了。如果有人能帮我解决这个问题,我会很激动。这篇文章的代码来源于《绅士的伟大教程》: 代码如下: @interface ViewController () { BOOL _bannerIsVisible; ADBannerView *_adBanner; } @end @implementation ViewController - (void)viewDidLoad { [super v

我搜索了又搜索,并且在这段代码上做了很多尝试和错误,试图将广告横幅移动到屏幕顶部。已经一个星期没有进展了。如果有人能帮我解决这个问题,我会很激动。这篇文章的代码来源于《绅士的伟大教程》:

代码如下:

@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
更改此行:

_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坐标(从第一个坐标中删除(-)并将其添加到第二个坐标中),因为您目前拥有的坐标假定帧位于屏幕底部

希望这有帮助