我已经将UINavigation控制器子类化了。无论我需要呈现一个视图控制器,我只需将视图控制器设置为我的子类导航控制器的根视图控制器并在此子类导航控制器中显示(这在我的情况下是强制性的)。进一步的视图控制器被简单地推入Subclassed Navigation Controller。 此外,我也定制了我的UINavigator栏。 但是在我的一个视图控制器中,导航栏标题中存在异常行为。它动画异常。 Here is the link to this phenomenon
let storyBoard : UIStoryboard = UIStoryboard(name: "Master", bundle: nil)
let vc :TFChatViewController = storyBoard.instantiateViewController(withIdentifier: "TFChatViewController") as! TFChatViewController
let navController = TFPresentedNavigationController.init(rootViewController: vc)
self.present(navController, animated: true, completion: nil)
这是我设置我的uiNavigation Bar Items
的方法self.rightButton!.frame = CGRect(x: 0, y: 0, width: 100, height: 24)
UtilityFunctions .setViewBorder(self.rightButton!, withWidth: 5, andColor: UIColor.white)
self.rightButton?.cornerRadius = 3.0
self.rightButton!.setTitle(rightButtonType == .addfriends ? "ADD FRIENDS" : "", for: UIControlState())
self.rightButton!.titleLabel!.font = UIConfiguration.getUIFONTAPPREGULAR(sizeFont: 14)
self.rightButton!.addTarget(self, action: #selector(BaseViewController.rightNavigationButtonClicked(_:)), for: .touchUpInside)
self.rightButton?.contentMode = .scaleAspectFit
self.rightbtnItem = UIBarButtonItem(customView: rightButton!)
self.rightButton!.titleLabel!.font = UIConfiguration.getUIFONTBOLD(sizeFont: 14)
let negativeSpacer: UIBarButtonItem? = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
negativeSpacer?.width = ConstantDevices.IS_IOS_6 ? -6 : -8
self.navigationItem.setRightBarButtonItems([negativeSpacer!, rightbtnItem!], animated: false)
左键
self.leftButton = UIButton.init(type: UIButtonType.custom)
self.leftButton!.setTitle("", for: UIControlState())
self.leftbtnItem = UIBarButtonItem(customView: self.leftButton!)
let negativeSpacer: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
negativeSpacer.width = ConstantDevices.IS_IOS_6 ? -6 : -16
self.navigationItem.setLeftBarButtonItems([negativeSpacer, self.leftbtnItem!], animated: false)
self.leftButton?.isUserInteractionEnabled = true
self.leftButton?.isHidden = false
最后标题
self.navigationItem.title = title