我有一个信息按钮,作为我UIImagePickerController
的自定义叠加层的一部分。当您单击它时,我设置导航栏的外观(在UIImagePickerController
"演示文稿"中隐藏)并推送新的视图控制器:
- (IBAction)infoButtonPressed:(id)sender {
CameraHelpViewController *helpController = [[[CameraHelpViewController alloc] initWithNibName:@"CameraHelpViewController" bundle:nil] autorelease];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[ipc pushViewController:helpController animated:NO];
}
CameraHelpViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Web view loading
NSString *basePath = [[NSBundle mainBundle] resourcePath];
basePath = [basePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
basePath = [basePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString *HTMLfile =[[NSBundle mainBundle] pathForResource:@"camera_help" ofType:@"html"];
NSError *error;
NSString *stringFromPath = [[[NSString alloc] initWithContentsOfFile:HTMLfile encoding:NSUTF8StringEncoding error:&error] autorelease];
[webView loadHTMLString:stringFromPath baseURL:[NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//", basePath]]];
webView.backgroundColor = [UIColor blackColor];
webView.opaque = NO; // Prevents the white flash from occurring
[_activityIndicator startAnimating];
}
//UPDATE:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
更新,因为使用@ryancrunchi中的代码,导航栏按钮不会移动到视图中。相反,导航栏在视图加载后向上移动几秒钟。
我希望在新视图出现之前完全设置导航栏。我怎么能这样做?
答案 0 :(得分:0)
使用以下行:
[ipc setNavigationBarHidden:NO animated:YES];
[ipc pushViewController:helpController animated:NO];
您正在为导航栏设置动画,但是在没有动画的情况下显示helpController
。因此helpController
出现在导航栏之前,导航栏本身正在播放动画(延迟显示)。
如果您根本不想要动画,请将[ipc setNavigationBarHidden:NO animated:NO];
放在CameraHelpViewController
:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[ipc setNavigationBarHidden:NO animated:animated];
// or
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
并在视图消失时隐藏栏:
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[ipc setNavigationBarHidden:YES animated:animated];
// or
[self.navigationController setNavigationBarHidden:YES animated:animated];
}