Take a picture of a hidden UIView

I'm trying to take a hidden view, but I have a few problems. If I try to show it quickly by taking a picture and then returning it, I sometimes get a quick flicker on the screen, which is pretty annoying.

toCollectionViewCell.hidden = NO; UIView *toPlaceHolderSnapshot = [toCollectionViewCell resizableSnapshotViewFromRect:toCollectionViewCell.bounds afterScreenUpdates:YES withCapInsets:UIEdgeInsetsZero]; toCollectionViewCell.hidden = YES; 

I am sure the flicker is caused by afterScreenUpdates: YES, but I can’t imagine that this is the intended behavior.

I also tried to move the cell / view from the screen instead of hiding it, but I cannot be sure that this cell can be reloaded and therefore prematurely moved to its place.

Is there a way to take a hidden view or a smarter way to achieve this? I need this functionality during a custom transition animation, where I take the collection view cell out of the collection view and then put it back in place upon dismissal. I take pre / post snapshots and then switch between them during the animation.

Thanks!

+5
source share
2 answers

Add an additional container view to the hierarchy of your view. Hiding the container will have the same visual effect, but you can easily reduce the contents of the container.

+5
source

I also tried to move the cell / view from the screen instead of hiding it, but I cannot be sure that this cell can be reloaded and therefore prematurely moved to its place.

This approach is probably the easiest. As long as all your work is done in the main thread, the cell will not move during the snapshot.


You can also try to archive and then unlock the view (essentially copy it):

 id copyOfView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:originalView]]; UIView *viewCopy = (UIView *)copyOfView; viewCopy.hidden = NO; 

(All views in the hierarchy must comply with the NSCoding protocol.)


Finally, you can draw your cell before the UIImage and then display it in the UIImageView . Sample code here .

0
source

Source: https://habr.com/ru/post/1202684/


All Articles