ios - 在 2 个 ViewController 之间推送 - NavigationBar

标签 ios objective-c uiview uinavigationcontroller uinavigationbar

我试图从一个 VC 推送到另一个 - 这是 0 问题,但是 VC1 有一个橙色的 NavigationBar 而 VC2 有一个完全透明的 NavigationBar。我想在推送 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;
}];

我怎样才能以更有效和更好的方式解决这个问题?

谢谢! 埃里克

最佳答案

这样解决:

    // 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 block 之外设置clearColor使动画平滑十亿倍。现在它的动画效果很好

关于ios - 在 2 个 ViewController 之间推送 - NavigationBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26486439/

相关文章:

ios - 使用 xcbuild/xcrun 和 xcconfig 向 cordova ios 应用程序添加 64 位支持

c# - 如何与约束水平对齐?

ios - iPhone X 上 SceneKit + SpriteKit 覆盖的像素格式错误

iphone - 哪个网站最适合 IOS、Cocoa、Objective-C 的 wiki?

objective-c - 将 Storyboard中的 UIViewController 更改为 UITableViewController?

swift - 快速删除 View

iphone - 使用 UIPanGestureRecognizer 旋转矩形

ios - [自动布局]在父 View 的高度发生变化时将 UIView 附加到其父 View 的底部

ios - Firebase(电话身份验证)获取 iOS 错误 : register custom URL scheme

iphone - 使用动态行高时 UITableView 出现间隙