如何在ios swift的Uinavigation Bar中实现滑动标题?

时间:2015-07-20 18:59:21

标签: ios swift uinavigationcontroller uinavigationbar

我的要求是导航栏的标题必须从左向右滑动。我该怎么做这种类型的动画?我正在使用storyboard进行应用开发。 谢谢!

1 个答案:

答案 0 :(得分:2)

您可以将自定义UILabel创建为titleView,然后在viewDidAppear中为其设置动画,您的代码应如下所示(代码测试)

 override func viewDidAppear(animated: Bool) {

    /* Create custom label as titleView of the navigation controller */
    let titleLabel  = UILabel(frame: CGRectMake(0, 0, 50, 50))
    titleLabel.text =  "My Title"
    self.navigationItem.titleView = titleLabel

    /* Animate the label */
    let moveAnimation = CATransition()
    moveAnimation.duration = 0.5
    moveAnimation.type = kCATransitionPush
    titleLabel.layer.addAnimation(moveAnimation, forKey:"moveText")
}