简体   繁体   English

UITableView内容偏移量-64pt问题

[英]UITableView content offset -64pt issue

I am debugging table view and in my -viewDidLoad method I have: 我正在调试表视图,并在我的-viewDidLoad方法中具有:

<UITableView: 0x7b394600; frame = (0 0; 1024 768); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7983d2f0>; layer = <CALayer: 0x79836ca0>; contentOffset: {0, 0}>

but when I check the frame and content offset in -viewDidAppear method: 但是当我在-viewDidAppear方法中检查框架和内容偏移量时:

<UITableView: 0x7ab79c00; frame = (0 0; 1024 768); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7998f700>; layer = <CALayer: 0x7998f560>; contentOffset: {0, -64}>

I don't know how table get -64 for its offset. 我不知道表如何获得-64的偏移量。

There is just sequence of methods view did load and then view did appear but content offset magically changed for me. 视图只是加载了一系列方法,然后视图确实出现了,但是内容偏移量对我来说发生了神奇的变化。

What can be a reason? 可能是什么原因?

This is my viewDidLoad: 这是我的viewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    _theTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

    _theTableView.dataSource = self;
    _theTableView.delegate = self;

    [self.view addSubview:_theTableView];

    _theTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

    self.title = @"File Manager";
}

I have navigation bar, but weird that I see my table as it should be without shifting. 我有导航栏,但是很奇怪,我看到的表应该保持不变。 So looks perfect I see top cell and when I scroll to the bottom I see last cell. 这样看起来很完美,我看到了顶部的单元格,当我滚动到底部时,看到了最后一个单元格。 Even indicator says to me that content offset is 0. If I force set content offset {0, 0} then seems like first cell goes under navigation bar and vertical indicator starts not from the top but with some padding about 64 pt, but it's strange. 甚至指示器对我说内容偏移量为0。如果我强制设置内容偏移量{0,0},则似乎第一个单元格进入导航栏,垂直指示器不是从顶部开始,而是有大约64 pt的填充,但这很奇怪。

I suppose this is because of status bar and navigation bar. 我想这是因为状态栏和导航栏。 But if hardcoded create my offset and frame, it does not help me. 但是,如果进行硬编码创建偏移和框架,则对我没有帮助。 Seems like system does it form me automatically =) 好像系统会自动形成我=)

This is the default behaviour, look into automaticallyAdjustsScrollViewInsets : 这是默认行为,请automaticallyAdjustsScrollViewInsets查看: automaticallyAdjustsScrollViewInsets

Default value is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. 默认值为YES,它允许视图控制器根据状态栏,导航栏以及工具栏或选项卡栏占用的屏幕区域来调整其滚动视图插图。 Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy. 如果要自己管理滚动视图插图调整,例如在视图层次结构中有多个滚动视图时,请设置为NO。

…and other related things in iOS 7 UI Transition Guide . …以及《 iOS 7 UI过渡指南》中的其他相关内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM