打包一个转场动画的方法

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



































转载于:https://my.oschina.net/luhoney/blog/658871

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值