【问题标题】:Navigation Bar Jumping After Transition导航栏跳转后跳转
【发布时间】:2016-09-21 00:59:45
【问题描述】:

我正在制作一个使用标签栏在视图控制器之间导航的应用程序。我想添加一个过渡效果,当按下选项卡按钮时,它会在每个视图之间交叉溶解。我已经用UIView.transitionFromView 实现了这个转换,但是导航栏在转换过程中没有按预期工作。在第一次转换到视图期间,导航栏显示得太高,但一旦转换完成就会跳回原位。但是,下次切换到同一个视图时,导航栏在转换期间和转换后都在正确的位置。

我已经看到一个答案 here 来解决自定义动画的问题,但我不知道如何让它与我当前的实现一起工作。

我的问题 我已经看到通过将视图向下强制几个点(44 点)来解决问题的答案,但是有没有办法在不直接更改点的情况下做到这一点?这可能在第一次时有效,但当任何视图转换到第二次时,问题就会自行解决,因此如果您更改点,则会导致视图太低。

这是我的标签栏控制器和转换代码:

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

    }

}

问题如下:

【问题讨论】:

    标签: ios swift uikit uitabbarcontroller transition


    【解决方案1】:

    就我而言,请在过渡解决问题之前致电toView.layoutIfNeeded()

    【讨论】:

      【解决方案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
      
          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
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-03
        • 1970-01-01
        • 2011-06-04
        • 2012-03-01
        • 1970-01-01
        • 1970-01-01
        • 2019-03-12
        • 1970-01-01
        相关资源
        最近更新 更多