use*_*872 6 iphone objective-c iad ios7 sprite-kit
我知道至少有一个问题询问如何将iAd集成到sprite kit游戏中,但这不是我想要的.我正在寻找一个如何做的肖像版本.关于如何做到这一点似乎绝对有0个在线教程,所以我来到这里.有人可以告诉我如何在Sprite Kit游戏中简单地启用iAd吗?我已启用canDisplayBannerAds并已将该originalContentView属性用于我的UIView,但我一直在说崩溃
*由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [ViewController originalContentView]:无法识别的选择器发送到实例0x10a0a7410'
任何帮助将不胜感激,这是我的视图控制器中的代码
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.originalContentView;
//skView.showsFPS = YES;
//skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [MyScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
Run Code Online (Sandbox Code Playgroud)
use*_*872 10
对于那些不理解的人,以及那些将来参考的人,这里是我对我的Sprite Kit游戏的做法.
我使用Xcode中的SpriteKit模板创建了我的游戏项目,然后进入项目设置:

在"Link Binary With Libraries"部分中,只需确保点击+按钮,然后添加iAd框架即可.
完成后,转到您的视图控制器为您的Sprite Kit游戏,然后键入:
// at the top
#import <iAd/iAd.h>
// do this in .m, above @implementation
@interface YourViewControllerClassName ()
@property (nonatomic, strong) ADBannerView *banner;
@end
// after the implementation line
// if you're needing to do it horizontally, do:
- (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 = [[YourScene alloc] initWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height)];
[view presentScene:scene];
}
Run Code Online (Sandbox Code Playgroud)
如果您只是在正常的肖像中进行iAd,您可以执行上述代码,但您也可以使用 - (void)viewDidLoad代替......
现在是iAd出现的委托方法......
转到@implementation行上方的代码,然后进行编辑
// do this in .m, above @implementation
@interface YourViewControllerClassName () <ADBannerViewDelegate>
@property (nonatomic, strong) ADBannerView *banner;
@end
Run Code Online (Sandbox Code Playgroud)
现在,进入实现行,输入:
// NOTE: THIS CODE CAME FROM APPLE MOSTLY
// I DID EDIT IT, BUT THE CREDIT GOES TO APPLE'S DOCUMENTATION
// ON IAD
- (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];
}
}
Run Code Online (Sandbox Code Playgroud)
这就是iAd在SpriteKit游戏中实际工作所需的全部内容.我希望我能帮助那些读这篇文章的人.
| 归档时间: |
|
| 查看次数: |
5538 次 |
| 最近记录: |