效果
仔细观察,你会发现,秒钟的具有摆动效果哦 ^_^
源码
https://github.com/YouXianMing/ConfigCircleView
// // RotateAnimationView.h // Good // // Created by YouXianMing on 15/5/12. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> /** 动画类型的枚举值 */ typedef enum : NSUInteger { Normal = 0x19871220, // 普通动画类型 POP, // POP动画类型 Easing, // Easing动画类型 } ECircleAnimationType; @interface RotateAnimationView : UIView /** * 动画时间长度 (如果不设定,默认时间为1秒钟) */ @property (nonatomic) NSTimeInterval duration; /** * 起始圆角弧度 (如果不设定,默认值为0, M_PI表示顺时针360°) */ @property (nonatomic) CGFloat fromCircleRadian; /** * 结束圆角弧度 (如果不设定,默认值为M_PI,M_PI表示顺时针360°) */ @property (nonatomic) CGFloat toCircleRadian; /** * 执行动画效果 * * @param type 动画效果类型 * @param animated 是否执行动画 */ - (void)startCircleAnimationWithType:(ECircleAnimationType)type Animated:(BOOL)animated; @end
// // RotateAnimationView.m // Good // // Created by YouXianMing on 15/5/12. // Copyright (c) 2015年 YouXianMing. All rights reserved. // #import "RotateAnimationView.h" // 动画父类 #import "RotateAnimationTypes.h" // 动画子类 #import "NormalRotateType.h" #import "PopRotateType.h" #import "EasingRotateType.h" @implementation RotateAnimationView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // 配置默认值 [self configDefaultValue]; } return self; } /** * 配置默认值 */ - (void)configDefaultValue { self.duration = 1.f; self.fromCircleRadian = 0.f; self.toCircleRadian = M_PI; } - (void)startCircleAnimationWithType:(ECircleAnimationType)type Animated:(BOOL)animated; { if (animated) { // 将动画的实现延时到子类中去执行,策略模式 if (type == Normal) { // 普通动画类型 RotateAnimationTypes *animationType = [NormalRotateType new]; animationType.targetObject = self; [animationType startAnimation]; } else if (type == POP) { // POP动画类型 RotateAnimationTypes *animationType = [PopRotateType new]; animationType.targetObject = self; [animationType startAnimation]; } else if (type == Easing) { // Easing动画类型 RotateAnimationTypes *animationType = [EasingRotateType new]; animationType.targetObject = self; [animationType startAnimation]; } } else { // 直接旋转到_circleRadian的角度 self.layer.transform = CATransform3DMakeRotation(_toCircleRadian, 0, 0, 1); } } @end
说明
1. 此旋转动画极具扩展性
2. 用到了策略的设计模式,每一种动画类型都是一个策略类,要添加新的效果,添加新的策略类即可
3. 你可以用此控件封装出你喜欢的效果