設置時看起來很簡單,但我無法解釋爲什麼狀態欄和導航欄之間存在這種差距。另外,包含的視圖看起來好像可以正確對齊,並且它只是向下移動的導航欄。這個差距看起來像狀態欄的大小,所以我期望這與它有關,但我不知道是什麼。UINavigationController頂部有額外的狀態欄間隙
這裏是用於設置導航控制器的代碼:
- (void)viewDidLoad
{
[super viewDidLoad];
advancedVC = [[AdvancedSearchFormVC alloc] initWithNibName:@"AdvancedSearchForm" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:advancedVC];
nav.navigationBar.tintColor = [UIColor defaultNavBarTint];
nav.navigationBar.topItem.title = NSLocalizedString(@"SearchTitle", nil);
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"SearchButton", nil) style:UIBarButtonItemStylePlain target:self action:@selector(refreshPropertyList:)];
nav.navigationBar.topItem.rightBarButtonItem = searchButton;
self.view = nav.view;
}
的RootViewController的使用從XIB文件,其中我有模擬狀態欄,導航條的視圖,並且標籤欄。
請注意,這是iOS 5和更早版本之間存在差異的區域。如果你使用導航控制器的「canned」佈局,它是相當便攜的,但是如果你已經定製了它,那麼這兩個版本之間的事情會有很大的變化。 (我從來沒有完全明白造成這種差異的原因,但是您展示的是iOS 5上運行的iOS 4代碼的典型代碼。) – 2012-01-15 22:25:04
請參閱此問題的第一個答案http://stackoverflow.com/questions/5850705/why-do-navigation-appear-20-pixels-below-status-bar-in-the-view – CarmeloS 2013-04-03 06:52:57