我有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
后面是(0, 0)
?见下面的截图Scenario 1
.注意navBar
后面的蓝色色调
现在,我在导航堆栈上添加了一个viewController
,只需使用[self.navigationController pushViewController.....]
即可.我还有一个自定义UIView
,里面有tableView
.然而,我在这张桌子上面还有一个UILabel
,为了调试,我又给了它一个redColor
.这次我将标签的origin
设置为几乎与视图的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
后面.
注意,导航栏后面的红色色调.
我真的很想一致地对齐导航栏下方的子视图.我的问题是
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?