我的目标是在Game Over上显示一个“Share”按钮.轻击共享按钮应该呈现一个SLComposeVIEwController(Twitter Share).场景的内容不应该改变.
规定“游戏结束”的游戏逻辑生活在SKScene的子类SpriteMyScene.m中.
我可以在游戏中显示一个Share按钮:
-(voID)update:(CFTimeInterval)currentTime {if (gameOver){ UIbutton *button = [UIbutton buttonWithType:UIbuttonTypeRoundedRect]; [button addTarget:self action:@selector(sendToController) forControlEvents:UIControlEventtouchDown]; [button setTitle:@"Show VIEw" forState:UIControlStatenormal]; button.frame = CGRectMake(80.0,210.0,160.0,40.0); [self.vIEw addSubvIEw:button]; }}- (voID)sendToController{ NSLog(@"ok"); SpriteVIEwController *vIEwController = [SpriteVIEwController alloc]; [vIEwController openTweetSheet];}
我遇到困难是试图让showTweetbutton方法工作.我的SpriteVIEwController.m看起来像这样:
- (voID)openTweetSheet { SLComposeVIEwController *tweetSheet = [SLComposeVIEwController composeVIEwControllerForServiceType: SLServiceTypeTwitter]; // Sets the completion handler. Note that we don't kNow which thread the // block will be called on,so we need to ensure that any required UI // updates occur on the main queue tweetSheet.completionHandler = ^(SLComposeVIEwControllerResult result) { switch(result) { // This means the user cancelled without sending the Tweet case SLComposeVIEwControllerResultCancelled: break; // This means the user hit 'Send' case SLComposeVIEwControllerResultDone: break; } }; // Set the initial body of the Tweet [tweetSheet setinitialText:@"just setting up my twttr"]; // Adds an image to the Tweet. For demo purposes,assume we have an // image named 'larry.png' that we wish to attach if (![tweetSheet addImage:[UIImage imagenamed:@"larry.png"]]) { NSLog(@"Unable to add the image!"); } // Add an URL to the Tweet. You can add multiple URLs. if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){ NSLog(@"Unable to add the URL!"); } // Presents the Tweet Sheet to the user [self presentVIEwController:tweetSheet animated:NO completion:^{ NSLog(@"Tweet sheet has been presented."); }];}
我总是在日志中得到这样的东西:
解决方法 您正在创建一个新的视图控制器,但不会显示它:-[UIVIEw presentScene:]: unrecognized selector sent to instance 0x13e63d00 2013-10-17 18:40:01.611 Fix[33409:a0b] * Terminating app
due to uncaught exception ‘NSinvalidargumentexception’,reason:
‘-[UIVIEw presentScene:]: unrecognized selector sent to instance
0x13e63d00’
SpriteVIEwController *vIEwController = [SpriteVIEwController alloc];
我假设SpriteVIEwController是呈现您的SpriteMyScene,并且您想手动控制回呈现的SpriteVIEwController.
您需要在SpriteMyScene子类中保留对SpriteVIEwController的引用,然后在调用openTweetSheet时访问该引用.
在SpriteMyScene.h
@class SpriteVIEwController;@interface SpriteMyScene : SKScene@property (nonatomic,weak) SpriteVIEwController *spriteVIEwController;@end
在SpriteVIEwController.m
// somewhere you initialize your SpriteMyScene object,I'm going to call it myScenemyScene.spriteVIEwController = self;
在SpriteMyScene.m
#import "SpriteVIEwController.h"- (voID)sendToController{ NSLog(@"ok"); // use the already-created spriteVIEwController [_spriteVIEwController openTweetSheet];}总结
以上是内存溢出为你收集整理的ios – 如何从SKScene呈现UIViewController?全部内容,希望文章能够帮你解决ios – 如何从SKScene呈现UIViewController?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)