gpt4 book ai didi

iphone - ios - UICollectionView 在水平分页时更改默认偏移量

转载 作者:可可西里 更新时间:2023-11-01 03:26:44 24 4
gpt4 key购买 nike

我正在尝试使用 UICollectionView 在屏幕居中的当前 View 的左侧和右侧显示 View 。

我可以正确显示此内容,但水平分页不会以后续 View 为中心,因为它默认为框架的宽度,即 320.0。

UICollectionView 在哪里计算它在裁剪到下一页时使用的默认偏移值?

我想改变这个值。有一个更好的方法吗?本质上,我正在尝试重新创建在 iPhone 上的应用商店的搜索结果中使用的体验。

最佳答案

事实证明,我必须设置 pagingEnabled = NO 并使用以下代码覆盖 (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView:

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
if (self.lastQuestionOffset > scrollView.contentOffset.x)
self.currentPage = MAX(self.currentPage - 1, 0);
else if (self.lastQuestionOffset < scrollView.contentOffset.x)
self.currentPage = MIN(self.currentPage + 1, 2);

float questionOffset = 290.0 * self.currentPage;
self.lastQuestionOffset = questionOffset;
[self.collectionView setContentOffset:CGPointMake(questionOffset, 0) animated:YES];
}

这个答案有帮助: Paging UIScrollView with different page widths

关于iphone - ios - UICollectionView 在水平分页时更改默认偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14867473/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com