它显示像卡中的详细应用程序信息,并且它被分页.当中间的一个活动卡片和滚动视图的分页行为仍然完整时,我被困在如何使上一张和第二张卡片显示.
我已经尝试使用UICollectionVIEw并将clipSubvIEws设置为NO,希望它将显示上一页和下一页,但是一旦单元格离屏,单元格将被隐藏(从视图层次结构中移除),而不是显示.我认为这是UICollectionVIEw的flyweight模式(UICollectionVIEw的行为).有什么可能的想法?
干杯,
Rendy Pranata
解决方法 问题:UICollectionVIEw作为UIScrollVIEw的子类基本上是通过bounds.size的步幅来动画化它的边界.虽然这可能意味着你所要做的只是减少界限,同时保持框架更大,不幸的是,UICollectionVIEw不会将任何单元格超出其当前边界,从而破坏您的预览效果.解决方案:
>创建一个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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)