Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView's snapshotViewAfterScreenUpdates:, determine if afterScreenUpdates needs to be YES

If you call [view snapshotViewAfterScreenUpdates:NO] on a view that hasn't been displayed yet, you get:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

This goes away by changing the param to YES, which makes sense. Passing YES has a performance hit, and I don't need "after screen updates" unless it hasn't been displayed yet. Is there a way to know when passing in NO will cause that error, so that I can pass in YES only in that scenario?

I tried [view snapshotViewAfterScreenUpdates:view.layer.needsDisplay], but that didn't do it.

like image 439
livings124 Avatar asked Nov 01 '22 23:11

livings124


1 Answers

I don't think UIView exposes whether or not it has unrendered changes. I usually only pass NO when I know (based on context) that the view has already been displayed, such as when creating a snapshot for a view that is about to be removed.

like image 101
Austin Avatar answered Nov 15 '22 05:11

Austin