ios - ios中圆轮动画的实现

标签 ios objective-c animation uicollectionview uicollectionviewlayout

我必须做一个像这样的动画:

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

目前我正在尝试使用自定义 Collection View 布局和子类化 UICollectionViewLayout 来实现这一点。

有什么帮助或方法可以实现这一目标吗?

最佳答案

simple layout


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

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

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

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


由于时间限制,我选择了第二个变体,我发现的最佳 repo 是:

https://github.com/sarn/ARNRouletteWheelView


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

  1. scrollToItemAtIndexPath 无法正常工作并导致应用程序崩溃。修复它的合并请求:https://github.com/sarn/ARNRouletteWheelView/pull/3/commits/7056e4bac2a04f2c8208d6d43e25d62a848f032d

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

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

关于ios - ios中圆轮动画的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32309704/

相关文章:

ios - 使呈现的 View Controller 忽略并传递触摸事件

ios - 从 Objective-C AppDelegate 调用时,Swift UIViewController init 不执行

ios - 使用通知将 NSString 值从一个 ViewController 传递到另一个?

ios - 呈现另一个 View Controller 将 UITableView 滚动到顶部

jquery - 如何暂停正在运行的动画并使用jquery中的一个按钮运行另一个动画

ios - 识别 UIStoryboard

objective-c - REST Auth 的 Cocoa Base 64 实现

ios - react-native iOS 原生模块 : calling method that activates network indicator asynchronously

安卓背景动画滞后游戏

javascript - 按背景颜色剪辑文本