在2个视图控制器之间推送 - 导航栏

时间:2014-10-21 12:12:34

标签: ios objective-c uiview uinavigationcontroller uinavigationbar

我正试图从一个VC推送到另一个 - 这是0问题,但VC1有一个橙色的NavigationBar,而VC2有一个完全透明的NavigationBar。我想在push segue期间在2个不同的NavigationBars之间平滑过渡。然而,此刻 - 它出现了这个黑色滑动条,颜色没有很好地过渡。这是我的代码:

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;
}];

如何以更有效和更好的方式解决这个问题?

谢谢! 埃里克

1 个答案:

答案 0 :(得分:1)

解决这个问题:

    // 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使动画更加平滑十亿倍。现在它很好地激活了