【问题标题】:What do I have to do after setting contentInset or automaticallyAdjustsScrollViewInsets for it to actually beeing applied?设置 contentInset 或 automaticAdjustsScrollViewInsets 后我需要做什么才能实际应用它?
【发布时间】:2014-05-01 04:30:19
【问题描述】:

我有一个包含UIScrollView 的UIViewController。最初automaticallyAdjustsScrollViewInsets 没有设置(所以它应该默认为YES)。

在一些用户交互中,我将automaticallyAdjustsScrollViewInsets 设置为NO,因此我可以在滚动视图上设置自己的contentInset。

这样做之后什么都没有发生。之后我要打什么电话?

在滚动视图上调用 setNeedsDisplay 没有帮助。

【问题讨论】:

    标签: ios ios7 uiscrollview setneedsdisplay insets


    【解决方案1】:

    如果您希望滚动视图的初始显示包含初始内容偏移量,请在 viewDidLoad 中设置 contentInset 值。 如果您希望动态更改 contentInset 并同时更改 contentOffset,则需要在调整 contentInset 的同时调整 contentOffset。例如:

    // Adjust content inset and initial offset to account for the header
    UIEdgeInsets contentInset = self.collectionView.contentInset;
    contentInset.top += self.stickyHeaderView.bounds.size.height;
    self.collectionView.contentInset = contentInset;
    if (-1 * self.collectionView.contentOffset.y < contentInset.top) {
        CGPoint contentOffset = self.collectionView.contentOffset;
        contentOffset.y = -1*contentInset.top;
        [self.collectionView setContentOffset:contentOffset animated:YES];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      • 2012-07-13
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 2021-07-22
      相关资源
      最近更新 更多