我是Spritekit的新手,我正在创建一个游戏,其中我有一个共享按钮的图像,我希望用户点击它来显示UIActivityViewController
。我知道如何在UIKit中做到这一点,但在SpriteKit中却没有。
这是我的代码。
// var ShareButton : UIButton!
ShareButton = UIButton.init(frame: CGRectMake(self.view!.frame.size.width/2 - 80,self.view!.frame.size.height/2 + 140 , 163, 54))
ShareButton.setImage(UIImage(named: "share"), forState: UIControlState.Normal)
ShareButton.addTarget(self, action: "pressedShareButton:", forControlEvents: .TouchUpInside)
self.view!.addSubview(ShareButton)
func pressed(_ sender: UIButton!) {
let va = self.view?.window?.rootViewController
let myText = "Can you beat my score \(score) in this game. "
let activityVC:UIActivityViewController = UIActivityViewController(activityItems: [myText], applicationActivities: nil)
va?.present(activityVC, animated: true, completion: nil)
}