zoukankan      html  css  js  c++  java
  • ios -动画

     self.collectionview.pagingEnabled = YES;

        //1.CollectionView 添加长按手势

        UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longHandle:)];

        [ self.collectionview addGestureRecognizer:longTap];

     

    }

    //2.长按方法

    -(void)longHandle:(UILongPressGestureRecognizer *)gesture

    {

        switch (gesture.state) {

            case UIGestureRecognizerStateBegan:

            {

                NSIndexPath *indexPath = [self.collectionview indexPathForItemAtPoint:[gesture locationInView:self.collectionview]];

                if (indexPath == nil) {

                    break;

                }

                [self.collectionview beginInteractiveMovementForItemAtIndexPath:indexPath];

                //cell.layer添加抖动手势

                for (UICollectionViewCell *cell in [self.collectionview visibleCells]) {

                    [self starShake:cell];

                }

                break;

            }

            case UIGestureRecognizerStateChanged:

            {

                [self.collectionview updateInteractiveMovementTargetPosition:[gesture locationInView:self.collectionview]];

                break;

            }

            case UIGestureRecognizerStateEnded:

            {

                

                [self.collectionview endInteractiveMovement];

                //cell.layer移除抖动手势

                for (UICollectionViewCell *cell in [self.collectionview visibleCells]) {

                    [self stopShake:cell];

                }

                break;

            }

            default:

                [self.collectionview cancelInteractiveMovement];

                break;

        }

        

    }

     

    //抖动动画

    - (void)starShake:(UICollectionViewCell*)cell{

        

        CAKeyframeAnimation * keyAnimaion = [CAKeyframeAnimation animation];

        keyAnimaion.keyPath = @"transform.rotation";

        keyAnimaion.values = @[@(-3 / 180.0 * M_PI),@(3 /180.0 * M_PI),@(-3/ 180.0 * M_PI)];//度数转弧度

        keyAnimaion.removedOnCompletion = NO;

        keyAnimaion.fillMode = kCAFillModeForwards;

        keyAnimaion.duration = 0.3;

        keyAnimaion.repeatCount = MAXFLOAT;

        [cell.layer addAnimation:keyAnimaion forKey:@"cellShake"];

    }

    - (void)stopShake:(UICollectionViewCell*)cell{

        [cell.layer removeAnimationForKey:@"cellShake"];

    }

  • 相关阅读:
    Go jaegerde 应用【logger+gorm+grpc+http】
    Go gRPC 调试工具
    iris和xxl-job整合
    Go Grpc部署到 k8s【端口共享】
    rocketmq事务 go 采用rocketmq-client-go的实现
    Go Grpc部署到 k8s【负载均衡】
    ubuntu18安装Kubernetes 1.20.5
    k8s Python API
    go nacos服务发现
    k8s集群日志收集ELK和graylog
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8616143.html
Copyright © 2011-2022 走看看