I'm trying to take a screenshot of a SCNView to display elsewhere. Since SCNView inherits from UIView, I thought I could use a UIGraphicsImageRenderer
:
extension UIView {
// Using a function since `var image` might conflict with an existing variable
// (like on `UIImageView`)
func asImage() -> UIImage {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in
layer.render(in: rendererContext.cgContext)
}
}
}
When I attempt to use this code on an SCNView, it causes a blank (white) UIImage (of the correct bounds).
How do I take a screenshot of a SCNView correctly?