我有一个UIViewController
包含一个UIScrollView
. 最初automaticallyAdjustsScrollViewInsets
没有设置(所以它应该默认为YES
)。
在某些用户交互上我设置automaticallyAdjustsScrollViewInsets
为,所以我可以在滚动视图上NO
设置我自己的。contentInset
这样做之后什么也没有发生。之后我要打什么电话?
调用setNeedsDisplay
滚动视图没有帮助。
我有一个UIViewController
包含一个UIScrollView
. 最初automaticallyAdjustsScrollViewInsets
没有设置(所以它应该默认为YES
)。
在某些用户交互上我设置automaticallyAdjustsScrollViewInsets
为,所以我可以在滚动视图上NO
设置我自己的。contentInset
这样做之后什么也没有发生。之后我要打什么电话?
调用setNeedsDisplay
滚动视图没有帮助。
If you want your initial display of your scrollview to include an initial content offset, then set the contentInset value in viewDidLoad
.
If you wish to dynamically change the contentInset and have the contentOffset change as well, then you need to adjust the contentOffset at the same time as the contentInset. For example:
// 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];
}