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"];

    }

  • 相关阅读:
    Android 可拖拽的GridView效果实现, 长按可拖拽和item实时交换
    安卓开发中非常炫的效果集合
    Android开源项目分类汇总
    Linux vim 底下显示行号
    backslash and newline separated by space
    LinuxC语言读取文件,分割字符串,存入链表,放入另一个文件
    Linux C 知识 char型数字转换为int型 int型 转换为Char
    Linux 底下使用C 对文件进行遍历
    Xshell 中文乱码
    Linux底下的第一个C程序
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8616143.html
Copyright © 2011-2022 走看看