問題描述:
由于某些需求亡电,項(xiàng)目中的導(dǎo)航欄用的都是自定義的方式添加的函喉,而把uinavigationController默認(rèn)的navigationbar隱藏調(diào)了酪碘。在iOS10之前帖世,下面的那串代碼都能正常顯示,代碼如下:
CGRect frame =CGRectMake(0,0,CGRectGetWidth(self.view.frame),64);
_customNavigationBar= [[UINavigationBaralloc]initWithFrame:frame];
_customNavigationBar.barTintColor=G_Theme_NavBar_Color
_customNavigationBar.translucent=NO;
[self.view addSubView:_customNavigationBar];
但是在iOS11(xcode9.0-beta4)中:就會出現(xiàn)導(dǎo)航欄內(nèi)容靠上的問題棍苹,如圖:
查了一下iOS11最新的sdk无宿,沒找到可以調(diào)整這個(gè)的方法。果斷聯(lián)系apple的開發(fā)團(tuán)隊(duì)枢里,得到了以下的反饋內(nèi)容:
THe layout is incorrect. The navigation bar height should be 44pts tall (not 64) and the frame.origin.y should be placed at topLayoutGuide.height. Your navigation bar delegate should then implement -positionForBar: to return UIBarPositionTopAttached.
You can see how UINavigationController places the navigation bar as an example, but it is almost certainly simpler to just use a UINavigationController to get the navigation bar placed correctly instead.
最終解決代碼:
CGRect frame =CGRectMake(0,20,CGRectGetWidth(self.view.frame),44);//目前該項(xiàng)目中的所有界面都會顯示狀態(tài)欄懈贺,所以此處直接先死frame
_customNavigationBar= [[UINavigationBaralloc]initWithFrame:frame];
_customNavigationBar.barTintColor=G_Theme_NavBar_Color;
_customNavigationBar.translucent=NO;
_customNavigationBar.delegate=self;
- (UIBarPosition)positionForBar:(id)bar {
returnUIBarPositionTopAttached;
}