我正在使用自定義的segue以便在兩個視圖控制器之間轉換。這是我用於這些轉換之一的segue:在顯示目標視圖控制器之前自定義將Segue動畫變爲黑色
class SegueFromRight: UIStoryboardSegue{
override func perform() {
// Assign the source and destination views to local variables.
let src = self.source.view as UIView!
let dst = 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.
dst?.frame = CGRect(0.0, screenHeight, screenWidth, screenHeight)
// Access the app's key window and insert the destination view above the current (source) one.
let window = UIApplication.shared.keyWindow
window?.insertSubview(dst!, aboveSubview: src!)
// Animate the transition.
UIView.animate(withDuration: 0.4, animations: {() -> Void in
src?.frame = (src?.frame.offsetBy(dx: -screenWidth, dy: 0.0))!
dst?.frame = (dst?.frame.offsetBy(dx: -screenWidth, dy: 0.0))!
}) { (Finished) -> Void in
self.source.present(self.destination as UIViewController,
animated: false,
completion: nil)
}
}
}
segue完美地工作,但動畫不是我想要的。當它「推」目標視圖控制器時,它顯示爲黑色。只要動畫完成,它就會轉向實際的視圖控制器。我想這是因爲新的視圖控制器只在動畫完成後才加載。但是,我將如何去預加載新的視圖控制器,以便動畫看起來流暢? 展開的segue不顯示該黑色動畫,因爲目標視圖控制器(前一個源視圖控制器)當然已經加載。
不要忘記打電話'super.perform()' – erenkabakci