简体   繁体   English

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

[英]NavigationItem titleView is coming at left side for some time then move to Center

I am setting a custom view as titleView of the navigation. 我正在将自定义视图设置为导航的titleView。 When viewcontroller appear its title view comes at left side for a moment and then move to center,what could be wrong? 当viewcontroller出现时,它的标题视图会在左侧出现一段时间然后移动到中心,这可能是错的? I am using the following code 我使用以下代码

    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
}

Try to add constraints of autoresizing masks to your menu view to keep the view centered. 尝试将自动调整遮罩的约束添加到菜单视图以使视图居中。

Eg 例如

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

我有这个问题,并改变我的功能,自定义我的navigationItem从viewWillAppear()viewDidLoad()解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将navigationItem titleView的位置更改为左侧 - Changing the position of navigationItem titleView to left side 如何在NavigationItem titleView中将自定义视图居中 - How to center custom view from xib in navigationItem titleView 如何设置navigationItem.titleView图像水平居中? - How to set navigationItem.titleView image horizontal center? 为什么在presentmodalviewcontroller调用时,navigationItem.titleView会左对齐? - Why does navigationItem.titleView align left when presentmodalviewcontroller called? 如何让 iOS navigationItem.titleView 左对齐? - How to make iOS navigationItem.titleView align to the left? iOS-NavigationItem titleView首次加载时居中,然后固定在左上方 - iOS - NavigationItem titleView is centered on first load, but then becomes pinned to top left 在某些情况下如何设置具有标题视图的导航项目的标题 - How to set title of navigationitem which have titleview for some conditions 当有多个navigationItem.rightBarButtonItem时,navigationItem.titleView无法在中心渲染? - navigationItem.titleView can't render at the center when there are more than one navigationItem.rightBarButtonItem? 将更多按钮添加到navigationItem时,如何将我的navigationItem.titleView居中? - How can I center my navigationItem.titleView when I add more buttons to the navigationItem? 在navigationItem中居中titleView - centering titleView in navigationItem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM