automaticAdjustsScrollViewInsets不起作用 [英] automaticallyAdjustsScrollViewInsets not working

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

问题描述

我创建了一个非常简单的演示应用程序,用于测试的功能,自动调整ScrollViewInsets ,但是我的标签栏覆盖了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?

推荐答案

我认为 automaticAdjustsScrollViewInsets 仅当控制器 view UIScrollView (表视图为1)时才有效。

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

您的问题似乎是您的控制器的视图是常规 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 UIWebView 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.

这篇关于automaticAdjustsScrollViewInsets不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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