#StackBounty: #ios #swift #uiview #uiscrollview #rendering Snapshot scaled UIView

Bounty: 200

Snapshotting a UIView using UIGraphicsGetImageFromCurrentImageContext() and a variety of other approaches including the render(in:) and drawHierarchy(in: afterScreenUpdates:) functions works great when you need to render a regular ol’ view.

I have been unable to get any of this working properly when trying to draw a scaled UIView hierarchy. The view in question is a UIScrollView‘s content & zoom view.

The view and its superviews refuse to do any transforms just before the snapshot that would fix the scaling problem. The result is that the snapshot either looks like:

  • A) an unfortunately cropped view, with its origin in the upper left (as expected on iOS), but then only expanding to the un-transformed “bounds” of the view. If the view happens to have no zoom or scale transform this is okay, but that rarely if ever happens.
  • B) an oversized view with big black borders that match the transformed “frame” of the view. I’m assuming this happens due to some weirdness with snapshotting a scaled view’s frame.

TL;DR: Can’t snapshot / render a UIView after its been scaled and zoomed by a UIScrollView, despite attempts to transform or redraw before snapshotting.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.