自动调整滚动视图插入不起作用

编程入门 行业动态 更新时间:2024-10-21 10:28:35
本文介绍了自动调整滚动视图插入不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个非常简单的演示应用程序来测试 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 仅在您的控制器 view 是 UIScrollView 时才有效>(表视图是一个).

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.

更多推荐

自动调整滚动视图插入不起作用

本文发布于:2023-11-11 18:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   不起作用

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!