简体   繁体   中英

Push a uiviewcontroller with a clear navigation bar

I have a drunk that happens when I push a viewcontroller with a clear navigation bar. Or rather when I press the backbutton.

My app :

在此输入图像描述

I would like this result :

在此输入图像描述

My code :

DetailViewController -> ViewDidLoad

[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                             forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;

DetailViewController

- (void)viewDidDisappear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    self.navigationController.navigationBar.translucent = NO;
}

A while back I was looking to solve the exact same issue, and unfortunately never got it looking exactly like your mockup. However, setting the backgroundImage to nil on viewWillDisappear does help the transition a bit.

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController.navigationBar setBackgroundImage:nil                       
                                         forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = nil;

    self.navigationController.navigationBar.translucent = NO;
}

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