2017-04-07 59 views
0

我正在兩個視圖控制器上執行簡單的從右到左的轉換。動畫完美無缺,恰恰是我期望的結果。但是,由於呈現/呈現視圖控制器淡入/淡出,我在背景中出現黑色閃光。轉換期間CATransition漸變黑色

我的過渡:

let transition = CATransition() 
transition.duration = 2.25 // Slow duration to see the black. 
transition.type = kCATransitionPush 
transition.subtype = kCATransitionFromRight 
view.window!.layer.add(transition, forKey: kCATransition) 
present(vc, animated: false, completion: nil) 

,我讀了設置在AppDelegate中didFinishLaunchingWithOptions窗口顏色可以但是解決這個問題,這並不似乎做任何事情。 (黑的過渡過程中仍然可見。)

self.window!.backgroundColor = UIColor.white 

上獲得任何建議兩個VC的不持續期間的黑色閃爍轉型?謝謝。

回答

1

我以前在執行像prepare(for:sender:)以上那樣的自定義轉換時有完全相同的問題。我在閱讀A Beginner’s Guide to Animated Custom Segues in iOS 8後設法解決了這個問題。

故事板裏選擇您SEGUE,挑定製種類和應用自定義SegueFromBottom類:

enter image description here

這裏是斯威夫特3.

import UIKit 

class SegueFromBottom: 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))! 
     }, completion: { (Finished) -> Void in 
      self.source.present(self.destination as UIViewController, animated: false, completion: nil) 
     }) 
    } 
} 
更新的代碼