UITabBarController 每次加载时高度都会降低

UITabBarController height decreases everytime it's loaded

当我第一次加载我的应用程序并登录时。一切正常。

但是当我注销,然后重新登录时,我的视图高度已经降低了。这是错误的屏幕截图:

我一直没能找到原因。这是一个很难寻求帮助的问题,因为我无法指定导致问题的精确代码部分。不过我会努力的。

有问题的设置是这样的:

我有一个 containerViewController,有 2 个 childViewControllers,一个菜单和一个 UITabBarControllerUITabBarController 有 2 个 UIViewControllers

为了更好地解释它,这里有一个可视化表示。

_______________________

App Start -> 

NavigationController(rootViewController LandingPageVC)

   LandingPageVC -> push -> SignInVC(this is where I login from)

   SignInVC -> push -> ContainerViewController(this has my UITabBarController and my menu)

   ContainerViewController (sets up my menuTabBarController and menu)

        menuTabBarController (this tabBarController is used to switch out my content from the menu)

        SidePanelViewController (this is my menu)

   ContainerViewController -> push(signing out) -> LandingPageVC

_______________________

以下是我在调用成功登录时推送 containerViewController 的方式。

let mainTableViewController = ContainerViewController()
mainTableViewController.navigationItem.setHidesBackButton(true, animated: false)
navigationController!.pushViewController(mainTableViewController, animated: true)
menuEnabled = true

这是我用来注销的 containerViewController 调用的函数。

func signOut() {

    // Set up the landing page as the main viewcontroller again.
    let mainTableViewController = LandingPageVC()
    mainTableViewController.navigationItem.setHidesBackButton(true, animated: false)
    mainTableViewController.skipView = false
    self.navigationController!.pushViewController(mainTableViewController, animated: true)

    // Disable menu access
    menuEnabled = false
}

通过打印 ContainerViewController 和 menuTabBarController 的高度,我发现减少的是 UITabBarController 的高度,而不是 ContainerViewController。

这是与 UITabBarController 相关的代码

import UIKit
import QuartzCore

let menuTabBarController = UITabBarController()

var menuButton = UIBarButtonItem()

var menuEnabled = false

class ContainerViewController: UIViewController, CenterViewControllerDelegate, SidePanelViewControllerDelegate, UIGestureRecognizerDelegate {

    func needsSignOut(sender: SidePanelViewController) {
        // toggling left panel
        self.toggleLeftPanel()
        // signing out
        self.signOut()
    }


  var centerViewController: UITabBarController!

  var leftViewController: SidePanelViewController?

  let centerPanelExpandedOffset: CGFloat = 60

  override func viewDidLoad() {
    super.viewDidLoad()

    menuTabBarController.tabBar.hidden = true

    menuButton = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: self, action: "toggleLeftPanel")
    if let font = UIFont(name: "FontAwesome", size: 20) {
        menuButton.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
    }
    self.navigationItem.leftBarButtonItem = menuButton

    //let tabBarController = UITabBarController()
    let suggestionsVC = SuggestionsViewController()
    let testVC = detaiLSuggestion_VC()
    let controllers = [suggestionsVC,testVC]

    menuTabBarController.setViewControllers(controllers, animated: false)

    centerViewController = menuTabBarController
    view.addSubview(menuTabBarController.view)
    addChildViewController(menuTabBarController)

    //centerNavigationController.didMoveToParentViewController(self)
  }

  // MARK: CenterViewController delegate methods

  func toggleLeftPanel() {

    let notAlreadyExpanded = (currentState != .LeftPanelExpanded)

    if notAlreadyExpanded {
        addLeftPanelViewController()
    }

    animateLeftPanel(shouldExpand: notAlreadyExpanded)

  }

  func collapseSidePanels() {
    switch (currentState) {
    case .LeftPanelExpanded:
      toggleLeftPanel()
    default:
      break
    }
  }

  func addLeftPanelViewController() {
    if (leftViewController == nil) {
        leftViewController = SidePanelViewController()
        leftViewController!.delegate = self

        addChildSidePanelController(leftViewController!)
    }
  }

  func addChildSidePanelController(sidePanelController: SidePanelViewController) {

    view.insertSubview(sidePanelController.view, atIndex: 0)

    addChildViewController(sidePanelController)
    sidePanelController.didMoveToParentViewController(self)
  }

  func animateLeftPanel(#shouldExpand: Bool) {
    if (shouldExpand) {
      currentState = .LeftPanelExpanded

        animateCenterPanelXPosition(targetPosition: CGRectGetWidth(centerViewController.view.frame) - centerPanelExpandedOffset)
    } else {
      animateCenterPanelXPosition(targetPosition: 0) { finished in
        self.currentState = .BothCollapsed

        self.leftViewController!.view.removeFromSuperview()
        self.leftViewController = nil;
      }
    }
  }


  func animateCenterPanelXPosition(#targetPosition: CGFloat, completion: ((Bool) -> Void)! = nil) {
    UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .CurveEaseInOut, animations: {
        self.centerViewController.view.frame.origin.x = targetPosition
      }, completion: completion)
  }

任何帮助推断这是从哪里来的或者我可以如何修复它的帮助将不胜感激!我再次为愚蠢的代码道歉。如果我能够排除其中的一部分,我会进一步更新它。

rdelmar 在聊天中为我找到了解决方案。

问题已通过如下指定 menuTabBarController.view.frame 解决:

menuTabBarController.view.frame = self.view.frame