如何设置UICollectionView 初始偏移

2025-05-09 22:30:51
推荐回答(4个)
回答1:

_collectionView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0); // 向上偏移20;
和scrollview一样,设置IcontentInset的偏移量就行了

回答2:

在- (void)viewWillLayoutSubviews {}或者- (void)viewDidLayoutSubviews {}中设置:
_collectionView.contentOffset = CGPointMake(320, 0);

回答3:

- 如何设置UICollectionView 初始偏移 如题,我希望能够在进入UICollectionViewController的时候,collectionView的内容就已经滚动到我需要的位置

回答4:

_collectionView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0); // 向上偏移20;
和scrollview一样,设置IcontentInset的偏移量就行了.
如果要自定义flowLayout,推荐http://blog.csdn.net/chenyblog/article/details/44535753