2017-04-25 90 views
1

我將自定義視圖設置爲導航的titleView。當viewcontroller出現時,它的標題視圖會在左側出現一段時間,然後移動到中心,可能會出現什麼問題?我正在使用以下代碼NavigationItem titleView來到左側一段時間然後移動到中心

let itemImgs: [UIImage] = [UIImage(named: "MORE_Location")!, UIImage(named: "MORE_Department")!, UIImage(named: "By_Teams")!, UIImage(named: "MORE_Status")!] 
    self.navigationController?.navigationBar.isTranslucent = false 
    self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] 

    menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, containerView: self.navigationController!.view, title: AppMessage.EDEmployeePeople, items: items as [AnyObject], itemImgs: itemImgs) 
    menuView.cellHeight = 60 
    menuView.cellBackgroundColor = UIColor.red 
    menuView.cellSelectionColor = UIColor.clear 
    menuView.cellSeparatorColor = UIColor.clear 
    menuView.shouldKeepSelectedCellColor = false 
    menuView.cellTextLabelColor = UIColor.white 
    menuView.shouldChangeTitleText = false 
    menuView.cellTextLabelFont = UIFont(name: "Helvetica", size: 17) 

    if appNeedsAutoResize 
    { 
     menuView.cellTextLabelFont = UIUtils.getFontForApproprieteField(.subHeadline).font 
    } 

    menuView.cellTextLabelAlignment = .left // .Center // .Right // .Left 
    menuView.arrowPadding = 15 
    menuView.animationDuration = 0.5 
    menuView.maskBackgroundColor = UIColor.clear 
    menuView.maskBackgroundOpacity = 0.3 

    menuView.didSelectItemAtIndexHandler = {(indexPath: Int) ->() in 

     print("Did select item at index: \(indexPath)") 

     if indexPath == 3 
     { 
      let byStatusViewController = ByStatusViewController(nibName: "ByStatusViewController", bundle: nil) 
      //UIUtils.pushViewWhenHideBottom(self, anotherVC: byStatusViewController) 
      self.navigationController?.pushViewController(byStatusViewController, animated: true) 
     } 
     else 
     { 
      let dropVC = DepartmentViewController(nibName: "DepartmentViewController", bundle: nil) 
      switch indexPath 
      { 
      case 0: 
       dropVC.employeeGroupInfo = EmployeeGroupInfo.locationInfo 
       break 
      case 1: 
       dropVC.employeeGroupInfo = EmployeeGroupInfo.departmentInfo 
       break 
      default: 
       dropVC.employeeGroupInfo = EmployeeGroupInfo.teamInfo 
       break 
      } 

      // UIUtils.pushViewWhenHideBottom(self, anotherVC: dropVC) 
      self.navigationController?.pushViewController(dropVC, animated: true) 
     } 
    } 

    self.navigationItem.titleView = menuView 
} 

回答

0

嘗試將自動調整掩碼的約束添加到菜單視圖以保持視圖居中。

E.g.

menuView.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin] 
0

我有這個問題,改變了我的功能定製我的navigationItem從viewWillAppear()viewDidLoad()解決

相關問題