How to take screen shot programmatically (Swift, SpriteKit)

后端 未结 2 1094
醉酒成梦
醉酒成梦 2021-01-02 06:52

I tried what ever was suggested but the output was a white,blank screenshot. Which leads me to assume that I haven\'t added anything to the view. Here\'s how I\'m adding gra

2条回答
  •  悲哀的现实
    2021-01-02 07:10

    I think this question could be merged with this one Screenshotting on Iphone in swift only has a white background

    which seems the same

    EDIT:

    I think I found a solution. First read this post: How Do I Take a Screen Shot of a UIView?

    I create an Extensions.swift file in which I 'extended' the methods of a UIView using that link.

    After that I simply connect the following to my sprite-kit button

    let screenshot = self.view?.pb_takeSnapshot()
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
    

    Voilà, the image is in the camera roll!

提交回复
热议问题