简体   繁体   中英

Make UINavigationBar transparent animated during transition

I can do translucent UINavigationBar transparent using this code:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
    navigationController!.navigationBar.shadowImage = UIImage()
}

But if you try this, you'll notice bad effect during push animation transition. Navigation bar becomes transparent immediately, before left screen completely disappears.

But on the other side, if you try this code....

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)

    navigationController!.setNavigationBarHidden(true: animated: animated)
}

... animation will be perfect: navigation bar disappears only on the right screen, so transition animation looks good.

Is there any way to make UINavigationBar transparent like in the first snippet with animation effect like in the second snippet?

yes, you need to make a method in your code which makes a delay for how many seconds your app is opened for example: [self performSelector:@selector(delay) withObject:nil afterDelay:5.0]; this would make when your app opens, after 5 seconds it will run everything you put in the delay method. So, I would find the second or mess around when you want the UINavigationBar to be transparent and you could easily find the code to make the UINavigationBar transparent but I don't know it off the top of my head.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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