HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了可可触摸 – 启用预览和分页的UICollectionView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在App Store中显示搜索结果时,我正在尝试模仿苹果公司的功能. (参http://searchengineland.com/apple-app-search-shows-only-one-result-at-a-time-133818)

显示像卡中的详细应用程序信息,并且它被分页.当中间的一个活动卡片和滚动视图的分页行为仍然完整时,我被困在如何使上一张和第二张卡片显示.

我已经尝试使用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所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。