Screenshot showing up blank – Swift

update: Xcode 8.2.1 • Swift 3.0.2

You need to add the import statement and this extension to your game scene:

import UIKit 

extension UIView {
    var snapshot: UIImage? {
        UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
        defer { UIGraphicsEndImageContext() }
        drawHierarchy(in: bounds, afterScreenUpdates: true)
        return UIGraphicsGetImageFromCurrentImageContext()
    }
}

let myImage = view?.snapshot

Leave a Comment

tech