我的要求是导航栏的标题必须从左向右滑动。我该怎么做这种类型的动画?我正在使用storyboard进行应用开发。 谢谢!
答案 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")
}