iPhone自動(dòng)隱藏 顯示工具欄和導(dǎo)航條實(shí)例
iPhone自動(dòng)隱藏 顯示工具欄和導(dǎo)航條實(shí)例是本文要介紹的內(nèi)容,iphone里如何實(shí)現(xiàn)像圖片瀏覽那樣的自動(dòng)隱藏和導(dǎo)航條和工具欄呢?其實(shí)很簡(jiǎn)單,只需要設(shè)置toolbar和navigationBar的顯示和隱藏屬性就可以了。效果圖如下:
未隱藏的效果圖
隱藏后的效果圖
具體實(shí)現(xiàn)代碼如下
首先在viewDidLoad里設(shè)置toolBarHidden = NO, 默認(rèn)是YES(隱藏的),為了讓toolbar顯示,需要設(shè)置為NO(不隱藏)。
- (void)viewDidLoad
- {
- [super viewDidLoad];
- self.title = @"隱藏導(dǎo)航欄";
- // self.toolbarItems
- selfself.navigationController.toolbar.barStyle = self.toolBar.barStyle;
- self.navigationController.toolbarHidden = NO;
- [self.navigationController.toolbar setTranslucent:YES];
- self.toolbarItems = [[[NSMutableArray alloc] initWithArray:self.toolBar.items] autorelease];
- }
在點(diǎn)擊中間button的時(shí)候的顯示和隱藏navigation bar和toolBar
實(shí)現(xiàn)代碼如下:
- (IBAction)toggleNavigationBar:(id)sender {
- //Check the current state of the navigation bar...
- BOOL navBarState = [self.navigationController isNavigationBarHidden];
- //Set the navigationBarHidden to the opposite of the current state.
- [self.navigationController setNavigationBarHidden:!navBarState animated:YES];
- [self.navigationController setToolbarHidden:!navBarState animated:YES];
- //Change the label on the button.
- if (navBarState) {
- [button setTitle:@"隱藏 Navigationr and toolbar" forState:UIControlStateNormal];
- [button setTitle:@"隱藏 Navigation Bar toolbar" forState:UIControlStateHighlighted];
- } else {
- [button setTitle:@"顯示 Navigation Bar toolbar" forState:UIControlStateNormal];
- [button setTitle:@"顯示 Navigation Bar toolbar" forState:UIControlStateHighlighted];
- }
- }
這樣的效果有什么用呢,比如我們常見的電子書,點(diǎn)擊中間那塊區(qū)域的時(shí)候顯示一些設(shè)置和導(dǎo)航。
小結(jié):iPhone自動(dòng)隱藏 顯示工具欄和導(dǎo)航條實(shí)例的內(nèi)容介紹完了,希望本文對(duì)你有所幫助!
本文鏈接:http://www.cnblogs.com/likwo/archive/2011/06/12/2078760.htm