简体   繁体   English

iOS颜色过渡导航栏

[英]iOS Color Transition Navigation Bar

My main Navigation Bar Color is a dark red. 我的主要导航栏颜色是深红色。 But when I fullsize view a picture, I want to have a black one. 但是,当我查看全图时,我想要一个黑色的。 But it looks as the following: 但它看起来如下:

颜色过渡

Anybody knows why the transition isn't very smooth? 有人知道为什么过渡不是很顺利吗?

I set the color in the fullsize-image view controller in the viewWillAppear Method, and revert it to the red color in the viewWillDisappear Method. 我在viewWillAppear方法中的全尺寸图像视图控制器中设置颜色,然后在viewWillDisappear方法中将其还原为红色。

Hope you can help me. 希望您能够帮助我。

It is cross-fading your navigation bar because this is the only allowed animation for navigation bars. 交叉淡化导航栏,因为这是导航栏唯一允许的动画。 I don't think there's any other way to make it do a gradient. 我认为没有其他方法可以使其渐变。

Please, use this: 请使用此:

override func willMove(toParent parent: UIViewController?) {
    self.navigationController?.navigationBar.barTintColor = .red

}

This happens when you give give navigation bar color as clear color i guess but you can overcome this by declaring it in Appdelegate file so that it can be applied in all ViewControllers like below, 当您给导航栏颜色指定为清晰的颜色时,就会发生这种情况,但是您可以通过在Appdelegate文件中声明它来克服此问题,以便可以将其应用于所有如下所示的ViewController中,

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance.barTintColor = UIColor.red
UINavigationBar.appearance.tintColor = UIColor.white
UINavigationBar.appearance.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]

return true
}

i hope it helps you out.good luck. 我希望它可以帮助您。祝您好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM