• 支付宝五福实现 核心代码


    //准备开始布局

    - (void)prepareLayout {}

    //返回的是决定cell样式的数组

    - (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {    

        NSArray * attributes =  [super layoutAttributesForElementsInRect:rect];

        //计算中心点的contentOffset

        CGFloat centerX = self.collectionView.contentOffset.x + self.collectionView.bounds.size.width * 0.5;

        //获取每一个cell的布局属性

        for (UICollectionViewLayoutAttributes * attri in attributes) {

            //计算每一个cell中心与中心点的contentOffset距离

            CGFloat delat = ABS(attri.center.x - centerX);

           

            //计算比例

            CGFloat scales = 1 - delat / (self.collectionView.bounds.size.width);

            

            attri.transform = CGAffineTransformMakeScale(scales, scales);

        }   

        return attributes;

    }

    //实时刷新

    - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds {

        return YES;

    }

    //targetContentOffset 调整后的contentOffset

    //proposedContentOffset 滑动停止的contentOffset

    - (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset withScrollingVelocity:(CGPoint)velocity {

        

        // 计算最终的可见范围

        CGRect rect;

        rect.origin = proposedContentOffset;

        rect.size = self.collectionView.frame.size;

        

        // 取得cell的布局属性

        NSArray * attributes = [super layoutAttributesForElementsInRect:rect];

        

        CGFloat centerX = proposedContentOffset.x + self.collectionView.bounds.size.width * 0.5;

        

        //获取最小间距

        CGFloat minDetal = MAXFLOAT;

        

        for (UICollectionViewLayoutAttributes *attrs in attributes) {

            

            if (ABS(minDetal) > ABS(attrs.center.x - centerX)) {

                minDetal = attrs.center.x - centerX;

            }

        }

        // 在原有offset的基础上进行微调

        return CGPointMake(proposedContentOffset.x + minDetal, proposedContentOffset.y);

    }

  • 相关阅读:
    Jmeter beanshell preprocessor随机添加任意多个请求参数
    Jmeter 场景设计
    jmeter 参数化
    .net 匿名方法
    jmeter 运行脚本报错 java.net.BindException: Address already in use
    Jmeter mysql性能测试
    ngcordova 监控网络制式改变
    建立apk定时自动打包系统第一篇——Ant多渠道打包并指定打包目录和打包日期
    Kafka架构
    Linux命令
  • 原文地址:https://www.cnblogs.com/PSSSCode/p/5272046.html
Copyright © 2020-2023  润新知