我正在尝试从一个VC推送到另一个VC-这是0问题,但是VC1具有橙色的NavigationBar,而VC2具有完全透明的NavigationBar。我想在推推期间在2个不同的NavigationBar之间平滑过渡。但是,此刻-带有黑色的滑动条,并且颜色过渡不佳。这是我的代码:

VC1 viewWillAppear:

    // Set the BarTintColor to translucent and text colors to white
[UIView animateWithDuration:0.5 animations:^{
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
}];


VC 2 viewWillAppear:

    // Make the NavigationBar transparent
[UIView animateWithDuration:0.5 animations:^{
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
}];


我该如何以更有效和更好的方式解决此问题?

谢谢!
埃里克

最佳答案

像这样解决它:

    // Make the NavigationBar transparent
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.4 delay:0 usingSpringWithDamping:.8 initialSpringVelocity:1.5 options:UIViewAnimationOptionTransitionNone animations:^{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
}completion:^(BOOL finished) {
}];


在animateWithDuration块之外设置clearColor可使动画平滑十亿倍。现在它的动画效果很好

关于ios - 在2个View Controller之间移动-导航栏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26486439/

10-14 22:26