当我推/弹视图控制器时,有没有办法停止UINavigationBar上的titleView动画。每个屏幕的TitleView都相同(应用程序的徽标)。
目前,当我推送视图时,导航栏上的titleView也会随视图一起滑动。
答案 0 :(得分:0)
尝试,
[self.navigationController pushViewController:viewController animated:NO];
答案 1 :(得分:0)
- (void)viewDidLoad
{
self.navigationItem.title=@"";
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
答案 2 :(得分:0)
将每个视图控制器中导航项的标题设置为空字符串,并将UILabel
子视图添加到导航栏:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:self.navigationController.navigationBar.bounds];
titleLabel.font = [UIFont fontWithName:@"Avenir-Roman"
size:20.f];
titleLabel.text = @"TEST TITLE";
titleLabel.textAlignment = NSTextAlignmentCenter;
[self.navigationController.navigationBar addSubview:titleLabel];
这应该为您提供一个静态标题,在视图控制器之间切换时不会移动。
答案 3 :(得分:0)
<强>夫特强>
可行的解决方案是:
使用UINavigationController
委托方法查找 UIViewController 的显示时间。然后对于每个UIViewController,需要创建一个类似isInitialized
属性的布尔变量,它可以帮助您确定何时将UIViewController推入堆栈,或者何时将其显示在下一个视图控制器的后面。
您的FirstViewController
:
func navigationController(_ navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
if viewController == self {
if self.isInitialized {
var navigationBarAnimation = CATransition()
navigationBarAnimation.duration = 1.5
navigationBarAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
navigationBarAnimation.type = kCATransitionFade
navigationBarAnimation.subtype = kCATransitionFade
navigationBarAnimation.removedOnCompletion = true
self.navigationController?.navigationBar?.layer?.addAnimation(navigationBarAnimation, forKey: nil)
}
else
{
self.isInitialized = true;
}
}
}
func navigationController(_ navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
if viewController == self {
if self.isInitialized {
self.navigationController?.navigationBar?.layer?.removeAllAnimations()
}
}
}
您的SecondViewController
:
func navigationController(_ navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
if viewController == self {
if !self.isInitialized {
var navigationBarAnimation = CATransition()
navigationBarAnimation.duration = 1.5
navigationBarAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn)
navigationBarAnimation.type = kCATransitionFade
navigationBarAnimation.subtype = kCATransitionFade
navigationBarAnimation.removedOnCompletion = true
self.navigationController?.navigationBar?.layer?.addAnimation(navigationBarAnimation, forKey: nil)
self.isInitialized = true;
}
}
}
func navigationController(_ navigationController: UINavigationController, didShowViewController viewController: UIViewController, animated: Bool) {
if viewController == self {
if self.isInitialized {
self.navigationController?.navigationBar?.layer?.removeAllAnimations()
}
}
}