NavigationItem titleView在左侧出现一段时间然后移动到Center

时间:2017-04-25 15:04:23

标签: ios swift navigationbar

我正在将自定义视图设置为导航的titleView。当viewcontroller出现时,它的标题视图会在左侧出现一段时间然后移动到中心,这可能是错的?我使用以下代码

    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
}

2 个答案:

答案 0 :(得分:0)

尝试在菜单视图中添加自动调整遮罩的约束,以使视图居中。

E.g。

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

答案 1 :(得分:0)

我遇到了这个问题并更改了自定义导航项从viewWillAppear()viewDidLoad()已解决

的功能