jjzjj

ios - automaticallyAdjustsScrollViewInsets 不工作

coder 2023-07-24 原文

我创建了一个非常简单的演示应用程序来测试 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 仅在您的 Controller viewUIScrollView( TableView 是一个)时才有效。

你的问题似乎是你的 Controller 的 view 是一个普通的 UIView 而你的 UITableView 只是一个 subview ,所以你您必须:

  • 使 TableView 成为“根” View 。

  • 手动调整插图:

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

编辑:

尽管不是 Controller 的 Root View ,但 SDK 似乎能够调整一些 ScrollView 。

到目前为止它与 UIScrollViewUIWebViewscrollView 一起工作,当它们是索引 0.

无论如何,这可能会在未来的 iOS 版本中改变,所以您自己调整 insets 会更安全。

关于ios - automaticallyAdjustsScrollViewInsets 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069258/

有关ios - automaticallyAdjustsScrollViewInsets 不工作的更多相关文章

随机推荐