在sprite-kit游戏中可以有Twitter/Facebook分享按钮吗?
问题描述:
我完全失去了,我发现的所有教程都是用于故事板的iOS 6应用程序。我的问题是如果你可以在sprite-kit游戏中拥有twitter或者facebook分享功能吗?如果是的话,添加它的最佳方式是什么?我读过的很多教程使用视图控制器,但精灵套件使用场景,所以我有点困惑。在sprite-kit游戏中可以有Twitter/Facebook分享按钮吗?
谢谢。
答
这是twitter的答案。不客气!
1)在Build Phases选项卡下导入Social框架,然后将Binary与库链接。将这个代码在你想要在分享它的SKScene顶部
#import <Social/Social.h>
2)-(id)initWithSize:(CGSize)size
方法与此代码添加您的鸣叫按钮:
SKSpriteNode *tweetButton = [SKSpriteNode spriteNodeWithImageNamed:@"share"];
tweetButton.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)-150);
tweetButton.name = @"tweet";
[self addChild:tweetButton];
3)在touchesBegan:
方法把下面的代码来处理一下鸣叫按钮和作曲鸣叫
if ([node.name isEqualToString:@"tweet"]) {
// Create an instance of the Tweet Sheet
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:@"This is my tweet text!"];
// Adds an image to the Tweet. Image named image.png
if (![tweetSheet addImage:[UIImage imageNamed:@"image.png"]]) {
NSLog(@"Error: Unable to add image");
}
// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:@"http://twitter.com/"]]){
NSLog(@"Error: Unable to URL");
}
UIViewController *controller = self.view.window.rootViewController;
[controller presentViewController:tweetSheet animated: YES completion:nil];
}
作为SKViews子类或者UIViews或NSViews我会去和使用“旧”技术。只需继续(或显示)UIViewController。 – Akaino