Как установить, какой ViewController находится на вершине для пользовательского перехода в Swift? - PullRequest
0 голосов
/ 27 апреля 2019

Я пытаюсь создать пользовательский переход, обратный переходу по умолчанию в Xcode (это снизу вверх).Под этим я подразумеваю то, что я хочу, чтобы текущий VC исчез, а VC, за которым я выступаю, должен быть позади.Проблема в том, что в моем текущем коде виртуальный канал, на который выполняется переход, находится сверху, и поэтому моя последовательность не отображает анимацию, поскольку она скрыта за этим виртуальным компьютером.Как я могу сделать так, чтобы мой текущий VC был на вершине?

Мой код:

override func perform() {
    animateDown()
}

func animateDown() {
    var firstVCView = self.source.view
    var secondVCView = self.destination.view

    // 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, y: 0, 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: 2, animations: { () -> Void in
        secondVCView!.frame = firstVCView!.frame.offsetBy(/*secondVCView!.frame, */dx: 0.0, dy: screenHeight)

    }) { (Finished) -> Void in
        self.source.present(self.destination as! UIViewController,
                                                        animated: false,
                                                        completion: nil)
    }
}
...