2017-04-07 66 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) 
     }) 
    } 
} 
更新的代码