自定义Unwind Segue无法正常运行

时间:2019-01-16 16:18:09

标签: swift xcode segue uistoryboardsegue

我正在尝试制作一个自定义的简单segue,它可以自上而下滚动并反向滚动。 CustomSegue的segue工作完美,但是CustomSegueUnwind不能正常工作,它在动画时不会在source.view下方显示destination.view。 知道我的代码有什么问题吗?

问题视频:https://streamable.com/iv7zk

class CustomSegue: UIStoryboardSegue {
override func perform() {
    // Assign the source and destination views to local variables.
    let firstVCView = self.source.view as UIView
    let secondVCView = self.destination.view as UIView

    // Get the screen width and height.
    let screenWidth = UIScreen.main.bounds.size.width
    let screenHeight = UIScreen.main.bounds.size.height

    // Specify the initial position of the destination view.
    secondVCView.frame = CGRect(x: 0.0, y: -screenHeight, width: screenWidth, height: screenHeight)

    // Access the app's key window and insert the destination view above the current (source) one.
    let window = UIApplication.shared.keyWindow
    window?.insertSubview(secondVCView, aboveSubview: firstVCView)

    // Animate the transition.
    UIView.animate(withDuration: 0.4, animations: { () -> Void in
        firstVCView.frame = firstVCView.frame.offsetBy(dx: 0.0, dy: screenHeight)
        secondVCView.frame = secondVCView.frame.offsetBy(dx: 0.0, dy: screenHeight)

    }) { (Finished) -> Void in

        self.source.present(self.destination as UIViewController,
                                                        animated: false,
                                                        completion: nil)
    }

}




class CustomSegueUnwind: UIStoryboardSegue {
override func perform() {
    // Assign the source and destination views to local variables.
    let secondVCView = self.source.view as UIView
    let firstVCView = self.destination.view as UIView

    let screenHeight = UIScreen.main.bounds.size.height

    // Access the app's key window and insert the destination view above the current (source) one.
    let window = UIApplication.shared.keyWindow
    window?.insertSubview(firstVCView, aboveSubview: secondVCView)

    // Animate the transition.
    UIView.animate(withDuration: 0.4, animations: { () -> Void in
        firstVCView.frame = firstVCView.frame.offsetBy(dx: 0.0, dy: -screenHeight)
        secondVCView.frame = secondVCView.frame.offsetBy(dx: 0.0, dy: -screenHeight)

    }) { (Finished) -> Void in

        self.source.dismiss(animated: false, completion: nil)
    }
}

0 个答案:

没有答案