dan*_*ver 29 objective-c uiscrollview uitabbar ios ios7
我已经创建了一个非常简单的演示应用来测试其功能automaticallyAdjustsScrollViewInsets,但是我的标签栏覆盖了tableView的最后一个单元格.
我的AppDelegate代码:
UITabBarController *tabControl = [[UITabBarController alloc] init];
tabControl.tabBar.translucent = YES;
testViewController *test = [[testViewController alloc] init];
[tabControl setViewControllers:@[test]];
[self.window setRootViewController:tabControl];
Run Code Online (Sandbox Code Playgroud)
我的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;
}
Run Code Online (Sandbox Code Playgroud)
这是iOS 7中的错误吗?如果没有,我做错了什么?
Riv*_*era 54
我认为automaticallyAdjustsScrollViewInsets只有当你的控制器view是一个UIScrollView(表视图是一个)时才有效.
您的问题似乎是您的控制器view是常规的UIView而您UITableView只是一个子视图,所以您必须要么:
使表查看"根"视图.
手动调整插图:
UIEdgeInsets insets = UIEdgeInsetsMake(controller.topLayoutGuide.length,
0.0,
controller.bottomLayoutGuide.length,
0.0);
scrollView.contentInset = insets;
Run Code Online (Sandbox Code Playgroud)编辑:
看起来像SDK能够调整一些滚动视图,尽管不是控制器的根视图.
到目前为止,当它们是索引的子视图时,它与UIScrollViews和UIWebViews scrollView一起使用0.
无论如何,这可能会在未来的iOS版本中发生变化,因此您自己调整插图会更安全.
Rob*_*ert 21
您的视图控制器必须直接在UINavigaitonController的堆栈上automaticallyAdjustsScrollViewInsets才能工作(即不是子视图控制器)
如果它是导航堆栈上的另一个视图控制器的子视图控制器,则可以改为设置automaticallyAdjustsScrollViewInsets = NO父级.或者你可以这样做:
self.parentViewController.automaticallyAdjustsScrollViewInsets = NO;
Run Code Online (Sandbox Code Playgroud)
Dar*_*usV 15
我知道这篇文章有点陈旧但是我刚用iOS 11和swift 4解决了这个问题,我当前的问题是iOS11有一个新的属性来验证ScrollView存在时的插图,一个是contentInsetAdjustmentBehaviorScrollView的属性,默认属性是automatic我的代码是:
if #available(iOS 11, *) {
myScroll.contentInsetAdjustmentBehavior = .never
} else {
self.automaticallyAdjustsScrollViewInsets = false
}
Run Code Online (Sandbox Code Playgroud)
我希望这也解决你的问题......
| 归档时间: |
|
| 查看次数: |
31597 次 |
| 最近记录: |