2017-12-19 31 views
0

まず第一に、これは私のビューコントローラ/セグエの設定です: Screenshot of Interface Builderプッシュセグ後にソースビューコントローラが消えないようにするにはどうすればよいですか?

右側の3つのビューコントローラの背景ビューがソースビューコントローラが表示されている必要があり、それを通してUIVisualEffectViewsです。彼らはこのような様々なviewDidLoad() Sで添加した。次に、メインビューコントローラ(「ガベージ日」もの)の設定を介して見える

let blurEffect = UIBlurEffect(style: .dark) 
let blurEffectView = UIVisualEffectView(effect: blurEffect) 
blurEffectView.frame = self.view.bounds 
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

self.tableView.backgroundView = blurEffectView 

コントローラを表示するが、設定VCは、二つのたびにいずれかを消滅右端のVCは完全に画面に表示されます。ここでは、画面の記録です:

Screen recording of the source view controller dis- and reappearing

(グリッチを無視してください、私はこれをアップロードするために使用アプリは明らかにビデオを破損している)

私は技術的には、ショーセグエは "を持っていないことを取得します私は、ソースVCが消えないことを期待すべきではありませんが、カスタムセグを使わずにこの作業を行う方法がなければなりません。

答えて

1

ビューコントローラ間でカスタムトランジションを作成することをお勧めします。

私は、このクラスを書き、テスト:あなたのUINavigationControllerクラスで

class AnimationController: NSObject, UIViewControllerAnimatedTransitioning 
{ 
    var pushing = true 

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
     return 0.3 
    } 

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
     let duration = transitionDuration(using: transitionContext) 

     let toVc = transitionContext.viewController(forKey: .to)! 
     let toView = transitionContext.view(forKey: .to)! 

     let fromView = transitionContext.view(forKey: .from)! 

     let container = transitionContext.containerView 

     if pushing { 
      container.addSubview(fromView) 
      container.addSubview(toView) 
     } 

     var finalFrame = transitionContext.finalFrame(for: toVc) 
     if pushing { 
      finalFrame.origin.x = finalFrame.width 
      toView.frame = finalFrame 
      finalFrame.origin.x = 0 
     } else { 
      finalFrame.origin.x = finalFrame.width 
     } 

     UIView.animate(withDuration: duration, delay: 0, options: .curveEaseOut, animations: { 
      if self.pushing { 
       toView.frame = finalFrame 
      } else { 
       fromView.frame = finalFrame 
      } 
     }) { (_) in 
      transitionContext.completeTransition(true) 
      if self.pushing { 
       container.insertSubview(fromView, belowSubview: toView) 
      } else { 
       fromView.removeFromSuperview() 
      } 
     } 
    } 
} 

は、次の手順を実行します

class NavigationController: UINavigationController { 

    let animationController = AnimationController() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     delegate = self 
    } 
} 

そして、この拡張機能:

extension NavigationController: UINavigationControllerDelegate 
{ 
    func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 

     animationController.pushing = operation == .push 

     return animationController 
    } 
} 

しかし、これはあなたを作りますインタラクティブな解任ジェスチャーを失う(画面の左からスワイプして消す)あなたはそれを修正する必要があります。私が恐れていたものだ

+0

。トランジションコードをありがとう、しかし私はちょうどぼやけた背景を完全にドロップすると思う。 –

関連する問題