如果您对swiftspritekitFacebook分享按钮感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于swiftspritekitFacebook分享按钮的详细内容,我
如果您对swift spritekit Facebook分享按钮感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于swift spritekit Facebook分享按钮的详细内容,我们还将为您解答facebook分享功能的相关问题,并且为您提供关于html – Facebook分享按钮:如何实施、ios – SpriteKit,XCode 8,Swift 3 MGGetBoolAnswer在模拟器中不可用、ios – Swift SpriteKit委托模式、ios – Swift Spritekit等距地图触摸位置的有价值信息。
本文目录一览:- swift spritekit Facebook分享按钮(facebook分享功能)
- html – Facebook分享按钮:如何实施
- ios – SpriteKit,XCode 8,Swift 3 MGGetBoolAnswer在模拟器中不可用
- ios – Swift SpriteKit委托模式
- ios – Swift Spritekit等距地图触摸位置
swift spritekit Facebook分享按钮(facebook分享功能)
嘿,我的应用程序几乎可以发布了,但是我想添加一个Facebook分享按钮。事情是我不知道场景和ViewController之间的通信是如何工作的。我做了我的研究,但只在obj-
c中找到了像这样的代码
- (void)lkFaceBookShare { NSString *serviceType = SLServiceTypeFacebook; if (![SLComposeViewController isAvailableForServiceType:serviceType]) { [self showUnavailableAlertForServiceType:serviceType]; } else { SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:serviceType]; UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; CGRect rect = [keyWindow bounds]; UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.5f); [self.view drawViewHierarchyInRect:rect afterScreenUpdates:YES]; UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [composeViewController addImage:viewImage]; NSString *initalTextString = [NSString stringWithFormat:@"Let''s join together in the form of underground catch word go along with me!! Link: https://itunes.apple.com/us/app/uoi-hinh-bat-chu-gioi-duoi/id907330926?ls=1&mt=8"]; [composeViewController setInitialText:initalTextString]; UIViewController *vc = self.view.window.rootViewController; [vc presentViewController:composeViewController animated:YES completion:nil]; }}- (void)showUnavailableAlertForServiceType:(NSString *)serviceType{ NSString *serviceName = @""; if (serviceType == SLServiceTypeFacebook) { serviceName = @"Facebook"; } else if (serviceType == SLServiceTypeSinaWeibo) { serviceName = @"Sina Weibo"; } else if (serviceType == SLServiceTypeTwitter) { serviceName = @"Twitter"; } UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Account" message:[NSString stringWithFormat:@"Please go to the device settings and add a %@ account in order to share through that service", serviceName] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil]; [alertView show];}
我的经验和知识不足,无法迅速移植,因此我需要与此D相关的帮助:
谢谢
答案1
小编典典这是我不久前为twitter做的一些代码,现在仍然可以迅速使用。我在下面向您展示如何将其转换为Facebook。把它放在你的viewController中:
func showTweetSheet() { let tweetSheet = SLComposeViewController(forServiceType: SLServiceTypeTwitter) tweetSheet.completionHandler = { result in switch result { case SLComposeViewControllerResult.Cancelled: //Add code to deal with it being cancelled break case SLComposeViewControllerResult.Done: //Add code here to deal with it being completed //Remember that dimissing the view is done for you, and sending the tweet to social media is automatic too. You could use this to give in game rewards? break } } tweetSheet.setInitialText("Test Twitter") //The default text in the tweet tweetSheet.addImage(UIImage(named: "TestImage.png")) //Add an image if you like? tweetSheet.addURL(NSURL(string: "http://twitter.com")) //A url which takes you into safari if tapped on self.presentViewController(tweetSheet, animated: false, completion: { //Optional completion statement })}
将其转换为Facebook的,只是换SLServiceTypeTwitter
到SLServiceTypeFacebook
并重命名变量可读性。如果要从SKScene调用此方法,则必须以某种方式提醒viewController要其调用方法。
我的首选方法是使用NSNotificationCenter,以便我从场景中发布警报,并由viewController接收,从而触发一个方法。这也非常容易设置。在场景中,您需要将以下代码行放在要调用Facebook弹出窗口的位置:
NSNotificationCenter.defaultCenter().postNotificationName("WhateverYouWantToCallTheNotification", object: nil)
这会发出带有名称的通知。现在,在viewController中,您需要通过将以下代码放入viewDidLoad,viewDidAppear或类似内容中来订阅此警报。
NSNotificationCenter.defaultCenter().addObserver(self, selector: "ThisIsTheMethodName", name: "WhateverYouCalledTheAlertInTheOtherLineOfCode", object: nil)
现在,场景将与viewController通信,您将能够显示Facebook工作表。请记住用与您的项目相关的字符串替换我的字符串。希望这会有所帮助-
很抱歉,回答这么长!
html – Facebook分享按钮:如何实施
解决方法
你可以把那个Facebook分享图片放在那里,用href =“http://www.facebook.com/sharer.PHP?u=\u0026lt;your url>”
Facebook的按钮也允许共享.为您的网站生成的代码在official documentation中.
ios – SpriteKit,XCode 8,Swift 3 MGGetBoolAnswer在模拟器中不可用
这是完整的信息:
2016-09-14 19:28:51.042 SpaceGameDeluxe[3182:49139] SKUtil.m:
MGGetBoolAnswer is not available in the simulator.
解决方法
by fbroom on Sep 15,2016 1:22 PM
This is a harmless message. It will be removed in the next release. Sorry for the confusion.
https://forums.developer.apple.com/thread/62983
ios – Swift SpriteKit委托模式
我有1个GameViewController,1个StartScene和1个MenuScene
在我的GameViewController中,我有两个方法,我想从MenuScene调用.到目前为止,我一直在使用NSNotification,它工作正常但我正在尝试使用委托.
所以我在MenuScene中设置了一个协议
protocol MenuSceneDelegate { func gameOver() func showGameCenter() }
我比这样引用它
var menuSceneDelegate: MenuSceneDelegate?
在GameViewController中,我在顶部添加了MenuSceneDelegate.到目前为止,一切都很标准.但是我遇到的主要问题是当我在GameViewController中设置委托时就像这样
let skView = view as! SKView! var scene = StartScene(size: skView.bounds.size) skView.ignoresSiblingOrder = true scene.scaleMode = .Resizefill skView.presentScene(scene) scene.menuSceneDelegate = self //Sets delegate to StartScene not MenuScene
它只适用于StartScene.如何将GameViewController委托从StartScene设置为MenuScene.如果我首先展示MenuScene,一切正常.但是我首先介绍了StartScene,因此我试图了解如何将委托设置为MenuScene.
我试过下面这样的东西,但它不起作用,只是似乎没有
var menuScene = MenuScene(size: skView.bounds.size) menuScene.menuSceneDelegate = self
我将不胜感激任何帮助或支持.非常感谢你
解决方法
ios – Swift Spritekit等距地图触摸位置
它以等距地图开始,我设法绘制.
但是我在地图的不同瓷砖上获得精确的触摸位置时遇到了麻烦.
它有效,但有点不合适,似乎不一致.
这是我的功能:
class PlayScene: SKScene { let map = SKNode() override func didMovetoView(view: SKView) { let origin = view.frame.origin let mapOrigin = CGPointMake(origin.x + self.frame.width / 4,origin.y - self.frame.height / 4) let mapConfig: Int[][] = [[0,1,0],[0,[2,2,2],0]] drawMap(mapConfig,mapOrigin: mapOrigin) }
用:
func drawMap(mapConfig:Int[][],mapOrigin:CGPoint) { let tileHeight:CGFloat = 25.5 let numColumns:Int = 8 let numRows:Int = 8 var position = mapOrigin var column: Int = 0 var row: Int = 0 for column = 0; column < numColumns; column++ { for row = 0; row < numRows; row++ { position.x = mapOrigin.x + CGFloat(column) * tileHeight position.y = mapOrigin.y + CGFloat(row) * tileHeight let isoPosition = twoDToIso(position) placeTile(isoPosition,mapConfig: mapConfig[row][column]) } } self.addChild(map) } func placeTile(position:CGPoint,mapConfig:Int) { switch mapConfig { case 0: let sprite = SKSpriteNode(imageNamed:"grasstile") sprite.position = position sprite.setScale(0.1) sprite.name = "\(position)" self.map.addChild(sprite) case 1: let sprite = SKSpriteNode(imageNamed:"roadTile") sprite.position = position sprite.setScale(0.1) sprite.name = "\(position)" self.map.addChild(sprite) default: let sprite = SKSpriteNode(imageNamed:"roadTileLTR") sprite.position = position sprite.setScale(0.1) sprite.name = "\(position)" self.map.addChild(sprite) } }
然后我想隐藏我触摸的瓷砖(用于测试):
override func touchesBegan(touches: NSSet,withEvent event: UIEvent) { for touch: AnyObject in touches { let locationNode = touch.locationInNode(self) nodeAtPoint(locationNode).hidden = true } }
但它并不总是隐藏正确的瓷砖.
那我该怎么解决呢?我的代码是否根本错误(可能)?或者我需要以某种方式将位置转换为iso坐标?或者玩瓷砖位面罩?
无论如何,谢谢你的帮助!
解决方法
问题是您单击的节点大于显示的节点(它具有透明部分).有关该问题的更好解释,请参阅my question here.
以下是我如何解决它(抱歉代码在Objective-C中):
1.在tile的边缘之后创建一个CGPathRef(tileSize是纹理的大小).此代码适用于常规等距切片,而不是六边形,但想法是相同的.
// ObjC -(CGPathRef)createTextureFrame:(CGSize)tileSize { CGMutablePathRef path = CGPathCreateMutable(); CGPathMovetoPoint(path,NULL,-(self.tileSize.height / 2)); CGPathAddLinetoPoint(path,(self.tileSize.width / 2),0); CGPathAddLinetoPoint(path,(self.tileSize.height / 2)); CGPathAddLinetoPoint(path,-(self.tileSize.width / 2),0); CGPathCloseSubpath(path); return path; } // Swift func createTextureFrame(tileSize:CGSize) -> CGPathRef { CGMutablePathRef path = CGPathCreateMutable() CGPathMovetoPoint(path,nil,-(self.tileSize.height / 2)) CGPathAddLinetoPoint(path,0) CGPathAddLinetoPoint(path,(self.tileSize.height / 2)) CGPathAddLinetoPoint(path,0) CGPathCloseSubpath(path) return path }
2.创建一个函数,检查给定的点是否在CGPathRef(textureFrame)中.
// ObjC -(BOOL)isPointOnNode:(CGPoint)point { return CGPathContainsPoint(textureFrame,point,YES); } // Swift func isPointOnNode(point:CGPoint) -> Bool { return CGPathContainsPoint(textureFrame,YES) }
3.对于每个触摸的节点,检查我们所在的textureFrame.
// ObjC UITouch *touch = [touches anyObject]; NSArray *nodes = [self nodesAtPoint:[touch locationInNode:self]]; for (SKNode *node in nodes) { CGPoint locationInNode = [touch locationInNode:node]; if ([node isPointOnNode:locationInNode]) { node.hidden = YES; } } // Swift var touch = touches.anyObject() as UITouch var nodes = self.nodesAtPoint(touch.locationInNode(self)) for node in nodes as [SKNode] { var locationInNode = touch.locationInNode(node) if node.isPointOnNode() { node.hidden = true } }
我不知道它是否是最好的解决方案,但效果很好.
我希望它有帮助:)
编辑:添加了Swift版本的代码
今天关于swift spritekit Facebook分享按钮和facebook分享功能的分享就到这里,希望大家有所收获,若想了解更多关于html – Facebook分享按钮:如何实施、ios – SpriteKit,XCode 8,Swift 3 MGGetBoolAnswer在模拟器中不可用、ios – Swift SpriteKit委托模式、ios – Swift Spritekit等距地图触摸位置等相关知识,可以在本站进行查询。
本文标签: