旋转动画的封装

效果

 

仔细观察,你会发现,秒钟的具有摆动效果哦 ^_^

 

源码

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. 你可以用此控件封装出你喜欢的效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值