为什么UIScrollView将空间放在顶部而不会滚动到底部

我是新的Objective-C编程。

我正在使用UIScrollView上的一些标签,图像和文本视图。

我已经closures了Autolayout,并已经尝试了“调整滚动查看插图”(标题中描述的情况)和closures(不滚动)。

这是我插入viewDidLoad:

[scroller setScrollEnabled:YES]; [scroller setContentSize:CGSizeMake(320, 687)]; 

但我必须错过一些非常简单的事情。

1 …为什么UIScrollView将空间放在顶部

与故事板 – 转到视图控制器>属性检查器>取消选中调整滚动视图插入属性

使用代码 – 对于额外的空间设置viewController属性automaticallyAdjustsScrollViewInsets调整viewControllerNO ,默认情况下是YES

 self.automaticallyAdjustsScrollViewInsets = false; scroller.contentInset = UIEdgeInsetsZero; scroller.scrollIndicatorInsets = UIEdgeInsetsZero; scroller.contentOffset = CGPointMake(0.0, 0.0); 

2 …不滚动到底部

要让它滚动尝试在像CGSizeMake(320, 1687)大数字。 如果它的工作,这意味着你没有设置contentSize足够大,其所有的内容。

只要select你的视图控制器,并将显示的选项设置为false(取消选中)

ViewController检查器

Swift 3.0

 self.automaticallyAdjustsScrollViewInsets = false scrollView.contentInset = UIEdgeInsets.zero scrollView.scrollIndicatorInsets = UIEdgeInsets.zero; 

在您的视图.m文件中,使用此代码来解决此问题

 -(void)layoutSubviews{ // To fix iOS8 bug of scrollView autolayout if([[[[[UIDevice currentDevice]systemVersion] componentsSeparatedByString:@"."]objectAtIndex:0] integerValue] == 8){ [self.tableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; } } 

Swift 3.0

 self.automaticallyAdjustsScrollViewInsets = false scrollView.contentInset = UIEdgeInsets.zero scrollView.scrollIndicatorInsets = UIEdgeInsets.zero; scrollView.contentOffset = CGPoint(x: 0.0, y: 0.0); 

Swift 3 (自动布局)

  1. 将“布局边距”更改为显式
  2. 根据您的需要设置保证金

在这里输入图像说明

 if #available(iOS 11.0, *) { scrollView.contentInsetAdjustmentBehavior = .never } else { automaticallyAdjustsScrollViewInsets = false }