当你启动我的应用程序它将正常运行然后突然当iAd横幅弹出它重新启动游戏它将返回到标题屏幕重新启动所有进度:
这是我的ViewController.h
#import <UIKit/UIKit.h>
#import <SpriteKit/SpriteKit.h>
@interface ViewController : UIViewController
@end
这是ViewController.m
#import "ViewController.h"
#import "MyScene.h"
#import <iAd/iAd.h>
@interface ViewController () <ADBannerViewDelegate>
@property (nonatomic,strong) ADBannerView *banner;
@end
@implementation ViewController
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (banner.isBannerLoaded) {
[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];
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!banner.isBannerLoaded) {
[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];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = NO;
skView.showsNodeCount = NO;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
- (void) viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.banner = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.banner.delegate = self;
[self.banner sizeToFit];
self.canDisplayBannerAds = YES;
SKView *view = (SKView *)self.originalContentView;
SKScene *scene = [[MyScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
[view presentScene:scene];
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end
答案 0 :(得分:3)
我希望在iAd视图出现时再次调用viewWillLayoutSubviews
。
将NSLog放在那里进行验证。如果是这样,请尝试将其中的所有内容移至viewDidAppear
或viewWillAppear
。