UITabbarController
はUINavigationController
です。私はUIView
のサブクラスを持っていて、navController
のUIViewController
のview
として割り当てます。これはかなり標準的なものですよね?これは私がそれを行う方法なぜUITableViewControllerはUINavigationBarの下でUIViewControllerを拡張しますか?
_productCategoryView = [[ProductCategoryView alloc] initWithFrame:self.view.frame];
self.view = _productCategoryView;
あるこのview
は私がビューにself.backgroundColor = [UIColor blueColor]
を設定していますデバッグのためにUITableView
subView
として
_productCategoryTableView = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStylePlain];
_productCategoryTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_productCategoryTableView.backgroundColor = [UIColor clearColor];
[self addSubview:_productCategoryTableView];
を持っています。
tableView
の上記の初期化から、ビューとテーブルのframe
は同じだと思うかもしれません。しかし、iOS 7
で実行すると、ビューの起点はUINavigationBar
の後ろに設定されます。これは私のサブクラスでをUINavigationController
に設定しているために理解できます。しかし、私が理解していないのは、テーブルがnavBar
のすぐ下に座っていることです。 navBar
の後ろにある(0, 0)
から始めるべきではありませんか?以下のスクリーンショットScenario 1
を参照してください。私は単に[self.navigationController pushViewController.....]
を使用することにより、ナビゲーションスタック上の別のviewController
をpush
、今navBar
の背後にある青の色相に注目してください。繰り返しますが、UIView
にはtableView
のカスタムがあります。しかし、私もUILabel
がこのテーブルの上にあり、デバッグのために、私はredColor
を与えました。私は、ビューの
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);
とほぼ同じになるように、ラベルのorigin
を設定しています。この時間は、上記の論理で行く、ラベルが右に、目に見えるすべきですか?しかし今回はそうではありません。今回はラベルが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でビルドしていますか? –