我有UITabbarController个,里面有UINavigationController个.我有一个子类UIView,我在navController中指定为UIViewController中的view.这是很标准的东西,对吧?我就是这样做的

_productCategoryView = [[ProductCategoryView alloc] initWithFrame:self.view.frame];
self.view = _productCategoryView;

viewUITableViewsubView

_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后面的蓝色色调

情景1

现在,我在导航堆栈上添加了一个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后面.

场景-2

注意,导航栏后面的红色色调.

我真的很想一致地对齐导航栏下方的子视图.我的问题是

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?

推荐答案

默认情况下,UITableViewController的视图会自动插入到iOS7中,这样它们就不会从导航栏/状态栏下方开始.这是通过界面生成器中UITableViewController的"属性判断器"选项卡上的"调整滚动视图插入"设置或UIViewController的setAutomaticallyAdjustsScrollViewInsets:方法创建的控制器.

对于UIViewController的内容,如果不希望其视图的内容在顶栏/底栏下延伸,可以使用Interface Builder中的"顶栏/底栏下延伸边"设置.这可以通过edgesForExtendedLayoutwine 店访问.

Objective-c相关问答推荐

在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙

为什么在目标 c 的静态上下文中允许 self

如何向 UILabel 添加滚动功能

无法编译连接:错误是什么意思?

我可以以编程方式滚动到 UIPickerView 中所需的行吗?

我如何使用 initWithCoder 方法?

xcode storyboard Container View - 如何访问视图控制器

设置数据后调整 UICollectionView 单元格的大小

CFURLCopyResourcePropertyForKey 失败,因为通过 URL 没有方案

Cocoa 与 Cocoa Touch - 有什么区别?

代码问题:格式字符串不是字符串文字

我可以在 Objective-C switch 语句中声明变量吗?

导航返回时重新加载 UITableView?

NSString 中子字符串的出现次数?

通过点击状态栏滚动到 UITableView 的顶部

有没有办法在不使用 UINavigationController 的情况下更改 Storyboard 中 UINavigationBar 的高度?

即使在静音模式下也能在 iPhone 上播放声音

AVAudioPlayer 不播放任何声音

带有Go按钮而不是返回的 iOS 键盘

Xcode中私有方法的单元测试