2016-05-24 3 views
3

私はタブバーを使用してビューコントローラ間を移動するアプリケーションを作成しています。タブボタンを押したときに各ビュー間で交差するトランジションエフェクトを追加したかったのです。 UIView.transitionFromViewでこの移行を実装しましたが、移行中にナビゲーションバーが期待どおりに機能していません。ビューへの最初の遷移中、ナビゲーションバーは高すぎると表示されますが、トランジションが完了すると再び元に戻ります。ただし、次回同じビューに切り替えると、ナビゲーションバーがトランジション中およびトランジション後の正しい場所に配置されます。移行後にジャンプするナビゲーションバー

カスタムアニメーションの問題を解決するための回答hereがありましたが、現在の実装で動作させる方法を理解できませんでした。

私の質問 私はいくつかのポイント(44ポイント)でビューを下に強制することにより、問題を修正する答えを見てきましたが、直接のポイントを変更することなく、それを行う方法はありますか?これは初めて機能するかもしれませんが、ビューが2度目に遷移したときに問題が解決され、ポイントを変更するとビューが低すぎます。ここで

は、タブバーコントローラと移行のための私のコードです:

iPhone Recording

答えて

2

あなたはこのコードを試すことができます:

import UIKit 

class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.delegate = self 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    // Method used to detect when a tab bar button has been tapped 
    func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool { 

     // Creating the 'to' and 'from' views for the transition 
     let fromView = tabBarController.selectedViewController!.view 
     let toView = viewController.view 

     if fromView == toView { 
      // If views are the same, then don't do a transition 
      return false 
     } 

     self.view.userInteractionEnabled = false 
     UIView.transitionFromView(fromView, toView: toView, duration: 2.0, options: .TransitionCrossDissolve, completion: nil) 
     self.view.userInteractionEnabled = true 

     return true 

    } 

} 

そして、ここでは、問題は次のようになります

import UIKit 

class MainTabBarViewController: UITabBarController, UITabBarControllerDelegate { 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.delegate = self 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

// Method used to detect when a tab bar button has been tapped 
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool { 

    // Creating the 'to' and 'from' views for the transition 
    let fromView = tabBarController.selectedViewController!.view 
    let toView = viewController.view 

    if fromView == toView { 
     // If views are the same, then don't do a transition 
     return false 
    } 

    self.view.userInteractionEnabled = false 

    if let window = fromView.window { 
     let overlayView = UIScreen.mainScreen().snapshotViewAfterScreenUpdates(false) 
     viewController.view.addSubview(overlayView) 
     UIView.transitionFromView(fromView, toView: toView, duration: 2.0, options: .TransitionCrossDissolve, completion: { (finish) in 
      window.rootViewController = viewController 
      UIView.animateWithDuration(0.4, delay: 0.0, options: .TransitionCrossDissolve, animations: { 
       overlayView.alpha = 0 
       }, completion: { (finish) in 
        overlayView.removeFromSuperview() 
       }) 
      }) 
     } 

     self.view.userInteractionEnabled = true 

     return true 
    } 
} 
関連する問題