Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在共享表中共享屏幕截图_Swift_Sharing - Fatal编程技术网

Swift 在共享表中共享屏幕截图

Swift 在共享表中共享屏幕截图,swift,sharing,Swift,Sharing,我正在制作一款aracade风格的游戏,当玩家输了,我会让他们选择通过iOS共享表共享他们的分数。我想知道的是,我怎么能让他们在死后分享截图和一些文字呢。我已经知道如何让他们共享文本,但我也想要截图。我将其设置为这样,以便在玩家死亡时游戏会截图: func screenShotMethod() { //Create the UIImage UIGraphicsBeginImageContext(view!.frame.size) view!.layer.renderInC

我正在制作一款aracade风格的游戏,当玩家输了,我会让他们选择通过iOS共享表共享他们的分数。我想知道的是,我怎么能让他们在死后分享截图和一些文字呢。我已经知道如何让他们共享文本,但我也想要截图。我将其设置为这样,以便在玩家死亡时游戏会截图:

func screenShotMethod() {
    //Create the UIImage
    UIGraphicsBeginImageContext(view!.frame.size)
    view!.layer.renderInContext(UIGraphicsGetCurrentContext())
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    //Save it to the camera roll
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

    println("screenshot")
}
然后我在GameOver序列中运行此函数,如下所示:

    if gameOver == 0{

gameOver = 1

***screenShotMethod()***

movingObjects.speed = 0

movingObjects.removeFromParent()

backgroundMusicPlayer.stop()
现在我想做的是访问这个屏幕截图,这样它就可以在共享选项中使用,但是如果玩家不共享该分数,那么只要玩家点击replay,它就会被删除。现在我的共享设置如下:

if shareButton.containsPoint(location){

        UIGraphicsBeginImageContext(view!.frame.size)
        view!.layer.renderInContext(UIGraphicsGetCurrentContext())
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        //Save it to the camera roll
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

        println("screenshot")

        var postImage = UIImage(named: "\(image)")

        socialShare(sharingText: "I just got \(score) points in Deez Nuts! Bet you can't beat that! #DeezNuts", sharingImage: UIImage(named: "\(postImage)"), sharingURL: NSURL(string: "http://itunes.apple.com/app/"))


    }

请具体和直接,因为我是新开发的应用程序。如果你还没有注意到,我也在使用Swift。多谢各位

您只需要删除这一行

var postImage = UIImage(named: "\(image)")
因为图像已经是UIImage,所以只需使用sharingImage:image

socialShare(sharingText: "I just got \(score) points in Deez Nuts! Bet you can't beat that! #DeezNuts", sharingImage: image , sharingURL: NSURL(string: "http://itunes.apple.com/app/")!)

找不到socialShare,救命!找不到socialShare,救命!