在共享表中共享屏幕截图
Sharing screenshots in share sheets
我正在制作街机风格的游戏,当玩家输了时,我会让他们选择通过 iOS 分享 sheet 来分享他们的分数。我想知道的是,我怎样才能让他们分享他们死时的截图以及一些文字。我已经知道如何制作它以便他们共享文本,但我也想要屏幕截图。我这样设置,以便游戏在玩家死亡时立即截取屏幕截图:
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()
现在我想做的是访问此屏幕截图,以便它可以在共享选项中使用,但如果玩家不共享该分数,则在玩家点击重播后立即将其删除。现在我有这样的共享设置:
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)")
因为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/")!)
我正在制作街机风格的游戏,当玩家输了时,我会让他们选择通过 iOS 分享 sheet 来分享他们的分数。我想知道的是,我怎样才能让他们分享他们死时的截图以及一些文字。我已经知道如何制作它以便他们共享文本,但我也想要屏幕截图。我这样设置,以便游戏在玩家死亡时立即截取屏幕截图:
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()
现在我想做的是访问此屏幕截图,以便它可以在共享选项中使用,但如果玩家不共享该分数,则在玩家点击重播后立即将其删除。现在我有这样的共享设置:
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)")
因为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/")!)