Posts

Post not yet marked as solved
2 Replies
2.3k Views
On iOS, I'm trying to convert the contents of a view produced by snapshotView(afterScreenUpdates:) into a UIImage. At the point where I'm trying to do this, I no longer have the underlying objects that were rendered into the snapshot - I only have the snapshot view.Although this snapshot view displays correctly on the device screen at all times, I seem to be unable to convert it to an image to save to disk.For example, say I do something like: let ssView = someView.snapshotView(afterScreenUpdates:true)And then later, I want to convert ssView to a UIImage. I have tried all the usual patterns that work with other (non-snapshot) views such as: UIGraphicsBeginImageContext(ssView.frame.size) ssView.drawHierarchy(in: ssView.bounds, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()or let renderer = UIGraphicsImageRenderer(size: ssView.frame.size) let image = renderer.image { context in return ssView.layer.render(in: context.cgContext) }And many other variations... I've also tried to render the hierarchy from superviews of the snapshot view but no matter what I try, it doesn't work. Attempting to capture the snapshot view directly produces a blank image and if the parent view is captured, the portion of the screen where the snapshot view resides is blank.Does anyone have any idea how to make this work?Thanks,David
Posted
by jodpurr.
Last updated
.