我有UITabbarController
其中UINavigationController
在裏面。我有一個UIView
的子類,我在navController
中指定爲view
的UIViewController
。這是非常標準的東西,對吧?這就是我要做的事爲什麼UIViewController在UINavigationBar下擴展,而UITableViewController沒有?
_productCategoryView = [[ProductCategoryView alloc] initWithFrame:self.view.frame];
self.view = _productCategoryView;
這view
有一個UITableView
作爲subView
_productCategoryTableView = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStylePlain];
_productCategoryTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_productCategoryTableView.backgroundColor = [UIColor clearColor];
[self addSubview:_productCategoryTableView];
要進行調試的緣故,我在視圖中設置self.backgroundColor = [UIColor blueColor]
。
從tableView
的上述初始化中,人們可能會認爲視圖和表格的frame
是相同的。但是,當我在iOS 7
中運行時,視圖的原點設置在UINavigationBar
的後面。這是可以理解的,因爲我在UINavigationController
的子類中設置了self.navigationBar.translucent = YES;
。但我不明白的是,桌子坐在navBar
的下方?它不應該也從(0, 0)
開始,它落後於navBar
?請參閱下面的屏幕截圖Scenario 1
。請注意後面navBar
藍色色調現在,我push
另一viewController
導航堆棧上,只需使用[self.navigationController pushViewController.....]
。再次我有一個自定義UIView
其中tableView
。不過,我也有這個表上面的UILabel
,再次調試,我給它一個redColor
。這一次,我設置了標籤的origin
是因爲幾乎相同的觀點的
CGRect boundsInset = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(10, 10, 10, 10));
CGSize textSize = [_titleLabel.text sizeWithFont:_titleLabel.font
constrainedToSize:CGSizeMake(boundsInset.size.width, MAXFLOAT)
lineBreakMode:NSLineBreakByWordWrapping];
printSize(textSize);
_titleLabel.frame = CGRectMake(boundsInset.origin.x,
boundsInset.origin.y,
boundsInset.size.width,
textSize.height);
因此,通過上述邏輯去,標籤應該是可見的,對不對?但這次不是。這次標籤是在navBar
後面。
通知,後面的Navbar紅色色調。
我真的想一直對齊navBar下面的子視圖。我的問題是
1. How is the tableView offset by 64pixels (height of nav + status bar in iOS 7) automatically, even though it's frame is same as the view's?
2. Why does that not happen in the second view?
您是否正在使用Xcode 5和iOS7 SDK構建? –