I have wrote a FadeSegue
class that override perform
function from its super, UIStoryboardSegue
class.
import Foundation
import UIKit
class FadeSegue :UIStoryboardSegue{
override func perform() {
let screenShotView = UIImageView()
screenShotView.image = self.source.view.screenShot
screenShotView.frame = CGRect(x: 0, y: 0, width: self.destination.view.frame.width, height: self.destination.view.frame.height)
self.destination.view.addSubview(screenShotView)
super.perform()
self.source.transitionCoordinator?.animate(alongsideTransition: nil, completion: { (c) in
UIView.animate(withDuration: 0.3, animations: {
screenShotView.alpha = 0
}) { (status) in
screenShotView.removeFromSuperview()
}
})
}
}
extension UIView {
var screenShot: UIImage? {
UIGraphicsBeginImageContextWithOptions(bounds.size, false, 1.0);
if let _ = UIGraphicsGetCurrentContext() {
drawHierarchy(in: bounds, afterScreenUpdates: true)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenshot
}
return nil
}
}
When Animates
checkbox be unchecked in Attribute Inspector
, This code will work fine in iOS 10. But in iOS 11, completion
block of transitionCoordinator.animate
will never called and fade animation will freeze in middle of its progress.
I cannot find out what is wrong in my code for iOS 11.