abhishek
abhishek

Reputation: 77

How can I implement a sliding title in Uinavigation Bar in ios swift?

My requirement is that the title of the navigation bar must slide from left to right. How can I do this type of animations? I am using storyboard for my app development. Thanks!

Upvotes: 0

Views: 310

Answers (1)

Alaeddine
Alaeddine

Reputation: 6212

You can create a custom UILabel as a titleView and then animate it in viewDidAppear your code should looks like (code tested)

 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")
}

Upvotes: 2

Related Questions