我有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构建? –