UIView+FJView.h
#import <UIKit/UIKit.h>
//动画类型的宏
typedef enum: NSUInteger{
FJ_pageCurl , //向上翻页
FJ_pageUnCurl,//向下翻页
FJ_rippleEffect,//水滴
FJ_suckEffect,//收缩
FJ_cube,//立方体
FJ_oglFlip,//上下页翻转
FJ_fade,//交叉淡化过度
FJ_moveIn,//新视图移到旧视图上面
FJ_push,//新视图把就视图退出去
FJ_Reveal //将旧视图移开,显示下面的新视图
}FJTransitionType;
//动画方向的宏
typedef enum: NSUInteger{
FJ_UP,
FJ_DOWN,
FJ_LEFT,
FJ_RIGHT
}FJTransitionDirection;
@interface UIView(FJView)
//声明需要添加的方法
- (void) addTransitionAnimationWithDuration:(NSTimeInterval) duration animationType:(FJTransitionType) animationType
direction:(FJTransitionDirection) direction;
@end
UIView+FJView.m
#import "UIView+FJView.h"
@implementation UIView(FJView)
- (void)addTransitionAnimationWithDuration:(NSTimeInterval)duration animationType:(FJTransitionType)animationType direction:(FJTransitionDirection)direction{
//1.创建一个动画对象
CATransition *trAnimation = [CATransition animation];
//2.设置动画时间
trAnimation.duration = duration;
//3.设置动画类型
NSArray *animationTypeArray = @[ @"pageCurl",@"pageUnCurl",
@"rippleEffect",@"suckEffect",@"cube",@"oglFlip",
kCATransitionFade,kCATransitionMoveIn,
kCATransitionPush,kCATransitionReveal];
[trAnimation setType:animationTypeArray[animationType]];
// [trAnimation setType:animationTypeArray[animationType]];
//4.设置方向
NSArray *directionArray = @[@"fromUp",@"formDown",@"fromLeft",@"fromRight"];
[trAnimation setSubtype:directionArray[direction]];
//5.添加动画
[self.layer addAnimation:trAnimation forKey:nil];
}
@end