自动调整滚动视图插入不起作用 [英] automaticallyAdjustsScrollViewInsets not working

查看:17
本文介绍了自动调整滚动视图插入不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个非常简单的演示应用程序来测试 automaticallyAdjustsScrollViewInsets 的功能,但是 tableView 的最后一个单元格被我的标签栏覆盖了.

I've created an extremely simple demo app to test the functionality of automaticallyAdjustsScrollViewInsets, but the last cell of the tableView is covered by my tab bar.

我的 AppDelegate 代码:

My AppDelegate code:

UITabBarController *tabControl = [[UITabBarController alloc] init];
tabControl.tabBar.translucent = YES;
testViewController *test = [[testViewController alloc] init];
[tabControl setViewControllers:@[test]];

[self.window setRootViewController:tabControl];

我的 testViewController(UITableViewController 的子类)代码:

My testViewController (subclass of UITableViewController) Code:

- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = YES;
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.dataSource = self;
self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
//[self.view addSubview:self.tableView];

// Do any additional setup after loading the view.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
cell.textLabel.text = @"test";
return cell;
}

这是 iOS 7 中的错误吗?如果没有,我做错了什么?

Is this a bug in iOS 7? If not, what did I do wrong?

推荐答案

我认为 automaticallyAdjustsScrollViewInsets 仅在您的控制器 viewUIScrollView 时才有效>(表视图是一个).

I think that automaticallyAdjustsScrollViewInsets only works when your controllers view is a UIScrollView (a table view is one).

你的问题似乎是你的控制器的 view 是一个普通的 UIView 而你的 UITableView 只是一个子视图,所以你必须:

You're problem seems to be that your controller's view is a regular UIView and your UITableView is just a subview, so you'll have to either:

  • 使表格视图成为根"视图.

  • Make the table view the "root" view.

手动调整插图:

UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length,
                                       0.0,
                                       controller.bottomLayoutGuide.length,
                                       0.0);
scrollView.contentInset = insets;

似乎 SDK 能够调整一些滚动视图,尽管它不是控制器的根视图.

Seems like the SDK is capable of adjusting some scroll views despite not being the controller's root view.

到目前为止它适用于 UIScrollView's 和 UIWebView's scrollView 当它们是索引 0 的子视图时代码>.

So far It works with UIScrollView's and UIWebView's scrollView when they are the subview at index 0.

无论如何,这可能会在未来的 iOS 版本中发生变化,因此您自己调整插图会更安全.

Anyway this may change in future iOS releases, so you're safer adjusting insets yourself.

这篇关于自动调整滚动视图插入不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆