How to keep UINavigationController's UINavigationBar transparent when modally presenting a controller?
I've got a fullscreen view inside of a UINavigationController. When I attempt to present a modal view on top of it, the UINavigationBar changes to opaque, pushing down the content, before the modal view animates. How do I keep this from happening?
ContextMenuViewController *cmvc =
[[ContextMen开发者_如何学运维uViewController alloc] initWithNibName:nil bundle:nil];
[cmvc setDelegate:self];
UINavigationController *navControl =
[[UINavigationController alloc] initWithRootViewController:cmvc];
[cmvc release];
[navControl.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController presentModalViewController:navControl animated:YES];
[navControl release];
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleBlackTranslucent
animated:NO];
The UINavigationController's root view does not have any transparency (status bar nor UINavigationBar), only the pushed controllers have the transparency.
I created a video of the issue: http://www.youtube.com/watch?v=KSFvzTR5Ejk
Example source at: http://cl.ly/7lu2
I tried your code in a very small test project and didn't see the issue you describe. I suggest you do the same thing. Start with the Navigation-based Application template. In the main nib, check the navigation controller's Wants Full Screen and Resize View From Nib, and make its nav bar transparent. In the root view controller's nib, put a button that you can respond to, set up the action, and paste in your code. Create the ContextMenuViewController class; there is no need to give it a nib.
Run the app and press the button. The modal view slides into place, with a transparent nav bar, without affecting the transparency of the nav bar that already exists and without moving the existing content.
So now, once you've proved to yourself that it works in this simple project, it's just a question of locating what you're doing different from that in the real project.
Try setting the bar styles during viewDidLoad for the root View Controller.
HERE YOU GO )
OptionsViewController *detailViewController = [[OptionsViewController alloc] initWithNibName:@"OptionsViewController" bundle:nil];
UINavigationController *optionsController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
[detailViewController release];
optionsController.navigationBar.translucent = YES; optionsController.navigationBar.opaque = YES; optionsController.navigationBar.tintColor = [UIColor clearColor]; optionsController.navigationBar.backgroundColor = [UIColor clearColor];
optionsController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:optionsController animated:YES];
[optionsController release];
精彩评论