UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直觀詳解(擴展)


ios開發中如何隱藏各種bar

狀態條Status Bar

[UIApplication sharedApplication].statusBarHidden = YES;

或者

// iOS3.2+支持
[application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

 statusBarHidden屬性支持在iOS2.0+,setStatusBarHidden:animated:方法在iOS3.2中開始取消了,而采用了setStatusBarHidden:withAnimation:方法。

上述方法只能實現在程序跳過loading(即啟動畫面)的時候才能隱藏狀態欄。如果想要在啟動畫面開始即隱藏狀態欄,則要修改app的info.plist文件,新增UIStatusBarHidden鍵(Status bar is initially hidden),其值是YES。

同理:對於狀態欄的顏色改變,也要分別從兩處着手,代碼[[UIApplicationsharedApplicationsetStatusBarStyle:UIStatusBarStyleBlackOpaque];僅僅改變了啟動畫面之后的視圖上的狀態欄,要讓App應用在啟動畫面之時就改變默認顏色,則要修改info.plist文件,新增UIStatusBarStyle鍵(Status bar style),其值有Opaque black style、Transparent black style和默認的Gray style。

 

導航條Navigation Bar

[self.navigationController setNavigationBarHidden:YES];

 

選項卡TabBar

方法一:

[self.tabBarController.tabBar setHidden:YES];

此方法的問題:雖然tabBar欄被隱藏了,但該區域成一片空白區,無法被其他視圖使用。

方法二:
對於navigationController+tabBarController的結構,可以在push下一級的childController之前將childController的hidesBottomBarWhenPushed屬性設為YES。比如,可以在childController的初始化方法中做這件事,代碼如下:

復制代碼
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
self.hidesBottomBarWhenPushed = YES;
}
return self;
}
復制代碼

方法三:

復制代碼
- (void)makeTabBarHidden:(BOOL)hide
{
if ( [self.tabBarController.view.subviews count] < 2 )
{
return;
}
UIView *contentView;

if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
{
contentView = [self.tabBarController.view.subviews objectAtIndex:1];
}
else
{
contentView = [self.tabBarController.view.subviews objectAtIndex:0];
}
// [UIView beginAnimations:@"TabbarHide" context:nil];
if ( hide )
{
contentView.frame = self.tabBarController.view.bounds;
}
else
{
contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
self.tabBarController.view.bounds.origin.y,
self.tabBarController.view.bounds.size.width,
self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
}

self.tabBarController.tabBar.hidden = hide;
// [UIView commitAnimations];
}
復制代碼

 

時機

復制代碼
- (void)viewWillAppear:(BOOL)animated 
{
[self setFullScreen:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self setFullScreen:NO];
}
- (void)setFullScreen:(BOOL)fullScreen
{
// 狀態條
[UIApplication sharedApplication].statusBarHidden = fullScreen;
// 導航條
[self.navigationController setNavigationBarHidden:fullScreen];
// tabBar的隱藏通過在初始化方法中設置hidesBottomBarWhenPushed屬性來實現
}

 

參考:http://www.cnblogs.com/pengyingh/articles/2381725.html

 

 

 

 

 

設置UINavigationBar的透明度

方法1:

self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;

方法2:

[self.navigationController.navigationBar setAlpha:0.5];不過看到的是window的背景

 

NavigationBar在64位ios中的特性

//navigationBar的背景色設置為黃色   iphone5s 64位操作系統,使用下面的方法,將導致navigationBar的大小擴大一倍,self.view的位置整體下移一個navigationbar的距離

    //[self.navigationController.navigationBar setBackgroundImage:[ImageUtilities createImageWithColor:[ColorUtils colorWithHexString:orange_color]] forBarMetrics:UIBarMetricsDefault];

 

viewDidLoad和viewWillAppear的區別

NavigationController 在從BController  pop回AController時,如果 AController的View還在,程序是不會再執行AController的viewDidLoad方法的。但程序回執行AController的viewAppear方法,這就是為什么NavigationBar的很多定制化屬性,要寫在viewWillAppear中。而不是viewDidLoad中。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM