I have fully transparent a table and navigation controllers. Because of this, when pushing new view controllers the animation was broken. Therefore I added my own custom push transition which takes snapshot of the next view controller and animates that.
This no longer works on iOS10. snapshotView(afterScreenUpdates: true)
returns a view that is pure white. I also tried getting the snapshot with the old method through graphics context and it didn't work too.
How can I be sure that the view being pushed to the navigation controller is loaded before snapshotView? Or is there a better way to solve this? This is a breaking change for me unfortunately..
I want to just say that this is strictly an iPhone 7 simulator and iPhone 7+ simulator issue. The issue will not appear on a real device. If you need to fix this for the simulator here is a work around I found in Pod: https://github.com/NewAmsterdamLabs/ZOZolaZoomTransition/
- (UIImage *)zo_snapshot {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, [UIScreen mainScreen].scale);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.layer renderInContext:context];
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return snapshot;
}
This extension should fix the issue
extension UIView {
/// Replacement of `snapshotView` on iOS 10. Fixes the issue of `snapshotView` returning a blank white screen.
func snapshotImageView() -> UIImageView? {
UIGraphicsBeginImageContext(bounds.size)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
layer.render(in: context)
let viewImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return UIImageView(image: viewImage, highlightedImage: viewImage)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With