大佬教程收集整理的这篇文章主要介绍了可可触摸 – 启用预览和分页的UICollectionView,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
它显示像卡中的详细应用程序信息,并且它被分页.当中间的一个活动卡片和滚动视图的分页行为仍然完整时,我被困在如何使上一张和第二张卡片显示.
我已经尝试使用UICollectionView并将clipSubviews设置为NO,希望它将显示上一页和下一页,但是一旦单元格离屏,单元格将被隐藏(从视图层次结构中移除),而不是显示.我认为这是UICollectionView的flyweight模式(UICollectionView的行为).有什么可能的想法?
干杯,
Rendy Pranata
解决方案:
>创建一个UICollectionView,其中页面设置为NO并使用所需的帧.
>创建比UICollectionView的框架/边界小的UICollectionViewCells.在这个阶段,下一个单元格的一部分应显示在框架中.在实施下面的其他步骤之前,这应该是可见的.
>添加一个collectionView.contenTinset.left和右(我假设你的布局是水平的)等于contentOffSETVALue方法(如下所示为简单起见),以便将第一个和最后一个单元格对齐到中间.
>创建一个UICollectionViewFlowLayout,它覆盖给出停止点的方法,如下所示:
像这样:
-(CGFloat)contentOffSETVALue { return self.collectionView.bounds.size.width * 0.5f - self.itemSize.width * 0.5f; } - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVeLocity:(CGPoint)veLocity { static float EscapeVeLocity = 0.5f; // otherwise snap BACk to the middle NSArray* layoutAttributesArray = [self layoutAttributesForElementsInRect:self.collectionView.bounds]; if(layoutAttributesArray.count == 0) return proposedContentOffset; CGFloat currentBoundsCenterX = self.collectionView.contentOffset.x + self.collectionView.bounds.size.width * 0.5f; UICollectionViewLayoutAttributes* candidateNextLayoutAttributes = layoutAttributesArray.firstObject; for (UICollectionViewLayoutAttributes* layoutAttributes in layoutAttributesArray) { if ((layoutAttributes.representedElementCategory != UICollectionElementCategoryCell) || (layoutAttributes == candidateNextLayoutAttributes)) // skip the first comparison conTinue; if(veLocity.x > EscapeVeLocity || veLocity.x < -(EscapeVeLocity)) { if(veLocity.x > EscapeVeLocity && layoutAttributes.center.x > candidateNextLayoutAttributes.center.X) { candidateNextLayoutAttributes = layoutAttributes; } else if (veLocity.x < -(EscapeVeLocity) && layoutAttributes.center.x < candidateNextLayoutAttributes.center.X) { candidateNextLayoutAttributes = layoutAttributes; } } else { if(fabsf(currentBoundsCenterX - layoutAttributes.center.X) < fabsf(currentBoundsCenterX - candidateNextLayoutAttributes.center.X)) { candidateNextLayoutAttributes = layoutAttributes; } } } return CGPointMake(candidateNextLayoutAttributes.center.x - self.collectionView.bounds.size.width * 0.5f,proposedContentOffset.y); }
以上是大佬教程为你收集整理的可可触摸 – 启用预览和分页的UICollectionView全部内容,希望文章能够帮你解决可可触摸 – 启用预览和分页的UICollectionView所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。