【发布时间】:2013-10-09 05:11:48
【问题描述】:
我有UITabbarController 和UINavigationController。我有一个UIView 的子类,我在navController 中指定为UIViewController 的view。这是很标准的东西,对吧?我就是这样做的
_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 后面的红色调。
我真的很想始终对齐导航栏下方的子视图。我的问题是
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 进行构建?
标签: ios objective-c layout uiview ios7