用动画更改大型导航栏标题

时间:2019-11-06 02:44:10

标签: swift uinavigationbar

我正在使用此功能更改导航栏标题,但是它是在小导航标题的位置(在中间)完成的,我希望它完全在大导航标题的位置(具有相同的位置)完成字体和大小)。

func showNavigationTitleWithAnimation(){
    /// Add a custom navigation title
    let navigationBar = self.navigationController?.navigationBar
    let titleLabelView = UILabel.init(frame: CGRect(x: 0, y: 0, width: navigationBar!.frame.width/2, height: navigationBar!.frame.height))
    titleLabelView.backgroundColor = UIColor.clear
    titleLabelView.textAlignment = .center
    titleLabelView.textColor = UINavigationBar.appearance().tintColor
    titleLabelView.font = UIFont.boldSystemFont(ofSize: 34)
    titleLabelView.text = ""
    self.navigationItem.titleView = titleLabelView


    let titleAnimation = CATransition()
    titleAnimation.duration = 0.5
    titleAnimation.type = CATransitionType.push
    titleAnimation.subtype = CATransitionSubtype.fromBottom
    titleAnimation.timingFunction = CAMediaTimingFunction.init(name: CAMediaTimingFunctionName.easeInEaseOut)

    navigationItem.titleView!.layer.add(titleAnimation, forKey: "changeTitle")
    (navigationItem.titleView as! UILabel).text = "New Title"
}

有人可以帮我吗? 谢谢

0 个答案:

没有答案