Created
December 15, 2020 14:10
-
-
Save VictorZhang2014/b28af4240e1c8f0fd363d0023bc8a45c to your computer and use it in GitHub Desktop.
Get a snapshot or screenshot of visible UICollectionViewCell in UICollectionView - Swift 5.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UICollectionView { | |
// Snapshot of UICollectionView, wherever you scroll, it captures the visible cells on screen as an image | |
func snapshot() -> UIImage? { | |
UIGraphicsBeginImageContextWithOptions(self.frame.size, false, 0) | |
UIGraphicsBeginImageContext(bounds.size) | |
self.drawHierarchy(in: frame, afterScreenUpdates: true) | |
let screenshot = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return screenshot | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UICollectionView滑动到哪里,就捕捉那一片的可视视图截屏