【发布时间】:2014-03-15 08:03:41
【问题描述】:
我正在制作像 Flappy Bird 这样的游戏。如何呈现来自 SKScene 的 UIViewController? 首先,我告诉我的环境
- Mac OS X 10.9
- Xcode 5.0.2
- Sprite Kit(framework)、social.framework(framework) 已添加到我的项目中
我的目标是在游戏结束时显示“分享”按钮。点击分享按钮图像应该会显示一个 SLComposeViewController (Twitter Share)。场景内容不应改变。
我想解决以下问题并将显示从 GameOverScene 更改为 tweetSheet(display)
由 social.framework 组成。
问题
[self presentViewController:tweetSheet animated:YES completion:nil];
//Error:No visible @interface for 'GameOverScene' declares the selector "presentViewController":animated:completion:
我的编码文件如下(我提取了部分重要代码)。
ViewController.h
import <UIKit/UIKit.h>
import <SpriteKit/SpriteKit.h>
import <iAd/iAd.h>
@interface ViewController : UIViewController<ADBannerViewDelegate><br>
@end
GameOverScene.h
#import <SpriteKit/SpriteKit.h>
@class SpriteViewController;
@interface GameOverScene : SKScene {
}
@end
GameOverScene.m
#import "GameOverScene.h"
#import "NewGameScene.h"
#import "MainScene.h"
#import <Social/Social.h>
@implementation GameOverScene {
//The twitter button
SKSpriteNode *_twitterbutton;
}
- (id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size]) {
//Creating the twitterbutton with the twitterbutton image from Images.xcassets
_twitterbutton = [SKSpriteNode spriteNodeWithImageNamed:@"twitterbutton"];
[_twitterbutton setSize:CGSizeMake(50, 50)];
[_twitterbutton setPosition:CGPointMake(self.size.width/2, self.size.height/5 + 50)];
//Adding the twitter button
[self addChild:_twitterbutton];
//Again, this is important, otherwise we can't identify what button is pressed
_twitterbutton.name = @"twitterbutton";
[_twitterbutton setPosition:CGPointMake(self.size.width/2, self.size.height/5 + 50)]
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//Same as in NewGameScene menu
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
SKNode *node = [self nodeAtPoint:location];
//Is the twitter button touched?
if([node.name isEqualToString:@"twitterbutton"]){
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]){
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"TestTweet from the Game !!"];
[self presentViewController:tweetSheet animated:YES completion:nil];
**//Error:No visible @interface for 'GameOverScene' declares the selector "presentViewController":animated:completion:**
}
}
ViewControlloer.m
#import "ViewController.h"
#import "NewGameScene.h"
@implementation ViewController
//Loads the view onto our main class
- (void)loadView
{
self.view = [[SKView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
}
//Executes when view finishes loading
- (void)viewWillLayoutSubviews
{
[super viewDidLoad];
//Set the resize mode to flexible width and height
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
//Create our view from our original view
//Make sure to leave originalContentView in, otherwise the app will crash
SKView *skView = (SKView *)self.originalContentView;
//We create a new NewGameScene according to the current dimensions
SKScene *scene = [NewGameScene sceneWithSize:skView.bounds.size];
//Create a transition class with animation type fade and a duration of .4 seconds
SKTransition *transition = [SKTransition fadeWithDuration:.4];
//Present the menu view (NewGameScene) with our fade in transition
[skView presentScene:scene transition:transition];
}
@end
【问题讨论】:
-
这里粘贴了很多代码,我怀疑有人会阅读所有这些。阅读本指南,了解如何最好地呈现您的问题:stackoverflow.com/help/mcve 该过程也有助于您更好地理解它。
-
>>Henrik 谢谢你的建议!这是我第一次提交我的问题。如果你感到生气,我很抱歉。先生,我将使用您的有益建议,非常感谢您。 >>Theis 谢谢你的建议。不过,我是 Xcode 的初学者。我知道这篇文章并阅读了越来越多的内容,但是我无法理解……所以,我提交了这个问题。我该怎么办你认为如何阅读这篇文章??? stackoverflow.com/questions/19438719/…
-
@tomojiro 别担心,别生气,只是想帮助第一次发帖的人改进问题以获得更多答案。 :)
标签: ios7 uiviewcontroller sprite-kit flappy-bird-clone skscene