我创建了一个非常简单的演示应用程序来测试其功能automaticallyAdjustsScrollViewInsets
,但 tableView 的最后一个单元格被我的选项卡栏覆盖。
我的 AppDelegate 代码:
UITabBarController *tabControl = [[UITabBarController alloc] init];
tabControl.tabBar.translucent = YES;
testViewController *test = [[testViewController alloc] init];
[tabControl setViewControllers:@[test]];
[self.window setRootViewController:tabControl];
我的 testViewController ( UITableViewController 的子类)代码:
- (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 中的一个错误吗?如果不是,我做错了什么?
我觉得automaticallyAdjustsScrollViewInsets
仅当您的控制器有效时才有效view
is a UIScrollView
(表视图就是其中之一)。
你的问题似乎是你的控制器view
是一个常规的UIView
和你的UITableView
只是一个子视图,因此您必须:
使表视图成为“根”视图。
-
手动调整插图:
UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length,
0.0,
controller.bottomLayoutGuide.length,
0.0);
scrollView.contentInset = insets;
Edit:
看起来 SDK 能够调整一些滚动视图,尽管不是控制器的根视图。
到目前为止它适用于UIScrollView
's and UIWebView
's scrollView
当它们是索引处的子视图时0
.
无论如何,这可能会在未来的 iOS 版本中发生变化,因此您自己调整插图会更安全。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)