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

    }

  • 相关阅读:
    使用jq.lazyload.js,解决设置loading图片的问题
    Write your first jQuery plugin
    如何在Less中使用使用calc
    web页面在ios下不支持fixed可用absolute替代的方案
    JavaScript内存优化
    js监听文本框内容变化
    动态绑定事件on
    CSS秘密花园:多边框
    2020—2021—1学期20202405《网络空间安全导论》第一周学习总结
    2020—2021—1学期20202405《网络空间安全导论》第五周学习总结
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/8616143.html
Copyright © 2011-2022 走看看