2016-12-29 24 views
0

私のアプリケーションでは、TabBarController TransitionsはAppleの参照コードObjective-C linkSwift linkで実装されています。しかし、2つのタブ間で高速に切り替えると何度か空白の画面が表示されますが、スタックオーバーフローでは多くの回答を試みましたが、運はありませんでした。 TabBarController iOSで空白の画面が表示される

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)! 
    let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)! 

    let containerView = transitionContext.containerView 
    let fromView: UIView 
    let toView: UIView 

    // In iOS 8, the viewForKey: method was introduced to get views that the 
    // animator manipulates. This method should be preferred over accessing 
    // the view of the fromViewController/toViewController directly. 
    if #available(iOS 8.0, *) { 
     fromView = transitionContext.view(forKey: UITransitionContextViewKey.from)! 
     toView = transitionContext.view(forKey: UITransitionContextViewKey.to)! 
    } else { 
     fromView = fromViewController.view 
     toView = toViewController.view 
    } 

    let fromFrame = transitionContext.initialFrame(for: fromViewController) 
    let toFrame = transitionContext.finalFrame(for: toViewController) 

    // Based on the configured targetEdge, derive a normalized vector that will 
    // be used to offset the frame of the view controllers. 
    var offset: CGVector 
    if self.targetEdge == UIRectEdge.left { 
     offset = CGVector(dx: -1.0, dy: 0.0) 
    } else if self.targetEdge == .right { 
     offset = CGVector(dx: 1.0, dy: 0.0) 
    } else { 
     fatalError("targetEdge must be one of UIRectEdgeLeft, or UIRectEdgeRight.") 
    } 

    // The toView starts off-screen and slides in as the fromView slides out. 
    fromView.frame = fromFrame 
    toView.frame = toFrame.offsetBy(dx: toFrame.size.width * offset.dx * -1, 
     dy: toFrame.size.height * offset.dy * -1) 

    // We are responsible for adding the incoming view to the containerView. 
    containerView.addSubview(toView) 

    let transitionDuration = self.transitionDuration(using: transitionContext) 

    UIView.animate(withDuration: transitionDuration, animations: { 
     fromView.frame = fromFrame.offsetBy(dx: fromFrame.size.width * offset.dx, 
      dy: fromFrame.size.height * offset.dy) 
     toView.frame = toFrame 

     }, completion: {finshed in 
      let wasCancelled = transitionContext.transitionWasCancelled 
      // When we complete, tell the transition context 
      // passing along the BOOL that indicates whether the transition 
      // finished or not. 
      transitionContext.containerView.addSubview(toView) 
      transitionContext.completeTransition(!wasCancelled) 
    }) 
} 

スウィフト

を使用してTabBarControllerトランジションをしながら

は、以下のような画面があなたの2番目のタブのための UINavigationControllerを取っているように思え enter image description here

+0

黒い画面しかありませんか? –

+0

追加したスクリーンショットを一度確認してください。 –

+1

@AnjaneyuluBattulaストーリーボードのパターンは次のとおりです:タブバーコントローラー - >ナビゲーションコントローラー - >コントローラーを表示しますか? – Amanpreet

答えて

1

を撮影している参照用のコードの下に確認してください。しかし、何とかあなたの接続UINavigationControllerからのsecondViewControllerへの接続が失われます。あなたのシナリオにあるかもしれないストーリーボードの画像を確認してください。 the image of a storyboard

+0

実際これはシナリオではありません。可能であれば、私が質問したサンプルコードを確認してください。 –

関連する問題