1

我写了一个FadeSegue类,它覆盖perform了它的超UIStoryboardSegue类中的函数。

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
    }
}

Animates未选中复选框时Attribute Inspector,此代码将在 iOS 10 中正常工作。但在 iOS 11 中,将永远不会调用completionblocktransitionCoordinator.animate并且淡入淡出动画将在其进度中间冻结。

我无法找出我的 iOS 11 代码有什么问题。

4

0 回答 0