10

提案されたことを試してみましたが、出力は白くて空白のスクリーンショットでした。これにより、ビューに何も追加していないと思います。ビューにグラフィックを追加する方法は次のとおりです。addChild メソッドは SpriteKit に付属しており、SKSpriteNodes を取り込みます。

  addChild(background)
    addChild(rate)
    addChild(scoreLabel)
    addChild(share)
    addChild(playAgain)
    addChild(highScoreLabel)
    addChild(scoreBackground)
    addChild(highScoreBackground)

スクリーンショットを撮る方法は次のとおりです。

    UIGraphicsBeginImageContext(self.view!.bounds.size)
    self.view!.layer.renderInContext(UIGraphicsGetCurrentContext())
    let screenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)

どんな提案も役に立ちます

4

2 に答える 2

4

Swift 3 で解決した方法は次のとおりです。これにより、シーン内のすべてのノードがキャプチャされます。注: 以下のコードは、キャプチャ元のビューを表します。プロジェクトのビューで更新することをお勧めします。

func captureScreen() -> UIImage {
    UIGraphicsBeginImageContextWithOptions(yourview.bounds.size, true, 0)

    yourview.drawHierarchy(in: yourview.bounds, afterScreenUpdates: true)


    let image = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    return image
}
于 2016-09-18T05:15:32.343 に答える