ios中的圆轮动画实现

时间:2015-08-31 10:59:54

标签: ios objective-c animation uicollectionview uicollectionviewlayout

我必须做一个动画:

https://www.flickr.com/photos/134104584@N07/20409116003/in/datetaken/

目前,我正在尝试使用自定义集合视图布局和子类化UICollectionViewLayout来实现此目的。

任何帮助或方法来实现这一目标?

1 个答案:

答案 0 :(得分:1)

simple layout

我有同样的任务,那是我发现的:

  1. 根据Rounak Jain的精彩教程,您可以制作自己的解决方案。该教程可在此处获得:

    https://www.raywenderlich.com/107687/uicollectionview-custom-layout-tutorial-spinning-wheel

  2. 您可以重复使用现有代码。

  3. 由于时间限制,我选择了第二个版本,而我发现的最佳回购是:

      

    https://github.com/sarn/ARNRouletteWheelView

    用法非常简单,但有两个提示非常有用:

    1. scrollToItemAtIndexPath无效并且正在崩溃应用程序。 Pull请求修复它:https://github.com/sarn/ARNRouletteWheelView/pull/3/commits/7056e4bac2a04f2c8208d6d43e25d62a848f032d

    2. 如果要缩小项目并禁用项目本身的旋转(请参阅gif),可以在UICollectionViewCell子类中执行以下操作:

    3. wheel layout

      #import "ARNRouletteWheelCellScaledAndRotated.h"
      #import <ARNRouletteWheelView/ARNRouletteWheelLayoutAttributes.h>
      
      @implementation ARNRouletteWheelCellScaledAndRotated
      
      - (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
          [super applyLayoutAttributes:layoutAttributes];
          if(layoutAttributes != nil && [layoutAttributes isKindOfClass:[ARNRouletteWheelLayoutAttributes class]]) {
              ARNRouletteWheelLayoutAttributes *rouletteWheelLayoutAttributes = (ARNRouletteWheelLayoutAttributes *)layoutAttributes;
              self.layer.anchorPoint = rouletteWheelLayoutAttributes.anchorPoint;
      
              // update the Y center to reflect the anchor point
              CGPoint center = CGPointMake(self.center.x, self.center.y + ((rouletteWheelLayoutAttributes.anchorPoint.y - 0.5) * CGRectGetHeight(self.bounds)));
              self.center = center;
      
              // rotate back
              CGAffineTransform rotate = CGAffineTransformMakeRotation(-rouletteWheelLayoutAttributes.angle);
              // scale
              CGFloat scale = 1 - fabs(rouletteWheelLayoutAttributes.angle);
              CGAffineTransform translate = CGAffineTransformMakeScale(scale, scale);
              // Apply them to a view
              self.imageView.transform = CGAffineTransformConcat(translate, rotate);
          }
      }
      
      @end