bdunagan

Brian Dunagan

November 8 2009
iPhone Tip: Conditional Toolbar

For an iPhone app I'm developing, I wanted a toolbar at the bottom of the initial view, but I didn't want it appearing in the other views. I tried simply calling myUINavigationController.hidden, but the effect was a little jarring. UINavigationController has a great wrapper for that method that includes animation: setToolbarHidden:animated:. With animation, the toolbar smoothly slides in and out when going between the initial view and the other views. I inserted the method in UIViewController's viewWillAppear and viewWillDisappear.

// in a UIViewController subclass

- (void)viewWillAppear:(BOOL)animated {
	[self.navigationController setToolbarHidden:NO animated:YES];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
	[self.navigationController setToolbarHidden:YES animated:YES];
	[super viewWillDisappear:animated];
}
iPhone Tip: Automatic Focus for Text Input Blog Breadcrumbs: Relevance, Recognition, and Trust
LinkedIn GitHub Email