2017-04-07 8 views
0

2つのView Controllerで右から左への簡単な切り替えを行っています。アニメーションは完璧に動作し、正確に私の望む結果が得られます。しかし、提示/提示されたビューコントローラがフェードイン/フェードアウトするため、バックグラウンドで黒いフラッシュが表示されます。移行中のCAT遷移が黒くなる

マイ移行:

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 

2 VCのは、期間中に黒いちらつきなしで移行するようになって上の任意のアドバイス?ありがとう。

答えて

1

私は上記のようにカスタムトランジションを実行するときに全く同じ問題が発生していました。prepare(for:sender:)A Beginner’s Guide to Animated Custom Segues in iOS 8を読んで解決しました。ストーリーボードインサイド

は、あなたのセグエを選択カスタム種類を選択し、カスタム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) 
     }) 
    } 
} 
ための更新されたコードです