封装类中的方法:

 #import <Foundation/Foundation.h>

 #import <UIKit/UIKit.h>

 @interface AnimationEffect : NSObject

 /**

  *  push/pop转场动画封装

  *

  *  @param type           动画类型

  *  @param subType        动画子类型

  *  @param duration       动画时间

  *  @param timingFunction 动画定时函数属性

  *  @param theView        self.view  当前控制器视图

  *

  *  @return 返回一个动画

  */

 + (CATransition *)showAnimationType:(NSString *)type

                         withSubType:(NSString *)subType

                            duration:(CFTimeInterval)duration

                      timingFunction:(NSString *)timingFunction

                                view:(UIView *)theView;

 @end

封装方法的实现及参数说明:

 #import "AnimationEffect.h"

 @implementation AnimationEffect

 + (CATransition *)showAnimationType:(NSString *)type
withSubType:(NSString *)subType
duration:(CFTimeInterval)duration
timingFunction:(NSString *)timingFunction
view:(UIView *)theView
{ CATransition *animation = [CATransition animation];
/** delegate
*
* 动画的代理,如果你想在动画开始和结束的时候做一些事,可以设置此属性,它会自动回调两个代理方法.
*
* @see CAAnimationDelegate (按下command键点击)
*/
animation.delegate = self;
/** duration
*
* 动画持续时间
*/
animation.duration = duration;
/** timingFunction
*
* 用于变化起点和终点之间的插值计算,形象点说它决定了动画运行的节奏,比如是均匀变化(相同时间变化量相同)还是
* 先快后慢,先慢后快还是先慢再快再慢.
*
* 动画的开始与结束的快慢,有五个预置分别为(下同):
* kCAMediaTimingFunctionLinear 线性,即匀速
* kCAMediaTimingFunctionEaseIn 先慢后快
* kCAMediaTimingFunctionEaseOut 先快后慢
* kCAMediaTimingFunctionEaseInEaseOut 先慢后快再慢
* kCAMediaTimingFunctionDefault 实际效果是动画中间比较快.
*/ /** timingFunction
*
* 当上面的预置不能满足你的需求的时候,你可以使用下面的两个方法来自定义你的timingFunction
* 具体参见下面的URL
*
* @see http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CAMediaTimingFunction_class/Introduction/Introduction.html
*
* + (id)functionWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
*
* - (id)initWithControlPoints:(float)c1x :(float)c1y :(float)c2x :(float)c2y;
*/
animation.timingFunction = [CAMediaTimingFunction functionWithName:timingFunction];
/** fillMode 此设置也可以作为参数传进来
*
* 决定当前对象过了非active时间段的行为,比如动画开始之前,动画结束之后.
* 预置为:
* kCAFillModeRemoved 默认,当动画开始前和动画结束后,动画对layer都没有影响,动画结束后,layer会恢复到之前的状态
* kCAFillModeForwards 当动画结束后,layer会一直保持着动画最后的状态
* kCAFillModeBackwards 和kCAFillModeForwards相对,具体参考上面的URL
* kCAFillModeBoth kCAFillModeForwards和kCAFillModeBackwards在一起的效果
*/
animation.fillMode = kCAFillModeForwards;
/** type
*
* 各种动画效果 其中除了'fade', `moveIn', `push' , `reveal' ,其他属于似有的API(我是这么认为的,可以点进去看下注释).
* ↑↑↑上面四个可以分别使用'kCATransitionFade', 'kCATransitionMoveIn', 'kCATransitionPush', 'kCATransitionReveal'来调用.
* @"cube" 立方体翻滚效果
* @"moveIn" 新视图移到旧视图上面
* @"reveal" 显露效果(将旧视图移开,显示下面的新视图)
* @"fade" 交叉淡化过渡(不支持过渡方向) (默认为此效果)
* @"pageCurl" 向上翻一页
* @"pageUnCurl" 向下翻一页
* @"suckEffect" 收缩效果,类似系统最小化窗口时的神奇效果(不支持过渡方向)
* @"rippleEffect" 滴水效果,(不支持过渡方向)
* @"oglFlip" 上下左右翻转效果
* @"rotate" 旋转效果
* @"push"
* @"cameraIrisHollowOpen" 相机镜头打开效果(不支持过渡方向)
* @"cameraIrisHollowClose" 相机镜头关上效果(不支持过渡方向)
*/ /** type
*
* kCATransitionFade 交叉淡化过渡
* kCATransitionMoveIn 新视图移到旧视图上面
* kCATransitionPush 新视图把旧视图推出去
* kCATransitionReveal 将旧视图移开,显示下面的新视图
*/
animation.type = type;
/** subtype
*
* 各种动画方向
*
* kCATransitionFromRight; 同字面意思(下同)
* kCATransitionFromLeft;
* kCATransitionFromTop;
* kCATransitionFromBottom;
*/ /** subtype
*
* 当type为@"rotate"(旋转)的时候,它也有几个对应的subtype,分别为:
* 90cw 逆时针旋转90°
* 90ccw 顺时针旋转90°
* 180cw 逆时针旋转180°
* 180ccw 顺时针旋转180°
*/
animation.subtype = subType;
[theView.layer addAnimation:animation forKey:nil];
return animation;
} @end

使用过程push和View:

 #import "ViewController.h"
#import "AnimationEffect.h"
#import "TestViewController.h" @interface ViewController () @property (nonatomic, strong)UIView *views; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; UIButton *bu = [UIButton buttonWithType:UIButtonTypeCustom];
bu.frame = CGRectMake(, , , );
[bu setBackgroundColor:[UIColor redColor]];
[self.view addSubview:bu];
[bu addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside]; self.views = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
self.views.backgroundColor = [UIColor orangeColor];
[self.view addSubview:self.views]; }
- (void)push{
//push的使用 // [self.navigationController.view.layer addAnimation:[AnimationEffect showAnimationType:@"cube"
// withSubType:kCATransitionFromRight
// duration:0.5f
// timingFunction:kCAMediaTimingFunctionEaseInEaseOut
// view:self.view]
// forKey:@"push"];
// TestViewController *tVC = [[TestViewController alloc]init];
// [self.navigationController pushViewController:tVC animated:YES]; // view的使用
[self.views.layer addAnimation:[AnimationEffect showAnimationType:@"cube"
withSubType:kCATransitionFromRight
duration:0.5f
timingFunction:kCAMediaTimingFunctionEaseInEaseOut
view:self.views]
forKey:@"animation"];
}

pop的使用过程:

 #import "TestViewController.h"
#import "AnimationEffect.h" @implementation TestViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor];
UIButton *bu = [UIButton buttonWithType:UIButtonTypeCustom];
bu.frame = CGRectMake(, , , );
[bu setBackgroundColor:[UIColor purpleColor]];
[self.view addSubview:bu];
[bu addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
} - (void)pop{ // pop的使用
[self.navigationController.view.layer addAnimation:[AnimationEffect showAnimationType:@"cube"
withSubType:kCATransitionFromLeft
duration:0.5f
timingFunction:kCAMediaTimingFunctionEaseInEaseOut
view:self.view]
forKey:@"push"]; [self.navigationController popViewControllerAnimated:YES];
} @end

后续将完善modal动画的封装。

本文GitHub地址https://github.com/zhangkiwi/iOS_SN_Animation

iOS_SN_push/pop转场动画封装和一般动画封装的更多相关文章

  1. UIKit封装的系统动画

    简介 在UIKit中,对UIView封装了很多类方法来进行简单的动画实现,在动画过程中,通过对属性值的修改来完成一系列的效果. 在IOS4以前,主要通过 + beginAnimation + setA ...

  2. uiview封装的基本动画

    基本动画的类型为 基本动画的节奏 UIViewAnimationOptionCurveEaseInOut            = 0 << 16, // default UIViewAn ...

  3. 第一百四十二节,JavaScript,封装库--运动动画和透明度动画

    JavaScript,封装库--运动动画和透明度动画 /** yi_dong_tou_ming()方法,说明 * * yi_dong_tou_ming()方法,将一个元素,进行一下动画操作 * 1,x ...

  4. JS---案例:手风琴 (利用封装好的动画函数)

    案例:手风琴     封装好的动画函数在common.js里面     //function getStyle(element, attr) {...}     //function animate( ...

  5. 【Flutter 实战】动画序列、共享动画、路由动画

    老孟导读:此篇文章是 Flutter 动画系列文章第四篇,本文介绍动画序列.共享动画.路由动画. 动画序列 Flutter中组合动画使用Interval,Interval继承自Curve,用法如下: ...

  6. iOS动画篇:UIView动画

    iOS的动画效果一直都很棒很,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,对于简单的应用场景,我们可以使用UIKit提供的动画来实现. UIView动画 ...

  7. IOS 动画专题 --iOS核心动画

    iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...

  8. iOS动画篇:核心动画

    转:http://www.cocoachina.com/ios/20160517/16290.html 基本概念 1.什么是核心动画 Core Animation(核心动画)是一组功能强大.效果华丽的 ...

  9. jQuery-1.9.1源码分析系列(十五) 动画处理——缓动动画核心Tween

    在jQuery内部函数Animation中调用到了createTweens()来创建缓动动画组,创建完成后的结果为: 可以看到上面的缓动动画组有四个原子动画组成.每一个原子动画的信息都包含在里面了. ...

随机推荐

  1. UIColor各种颜色转换

    1.Hex值颜色转换 #import <UIKit/UIKit.h> @interface UIColor (Extension) // 根据无符号的32位整数转换为对应的RGB颜色 + ...

  2. dbutils的使用Demo

    首先了解一下 Queryrunner.query    —————只可以执行select语句. Queryrunner.update  —————只可以接收update,delte,insert语句 ...

  3. (原创) jetson tk1 初始化

    1. 相关的网站: 1. Jetson TK1 support   https://developer.nvidia.com/jetson-tk1-support 2.official Wiki fo ...

  4. Java语言实现简单FTP软件------>FTP软件效果图预览之上传功能(三)

    下面展示一下上传功能的过程 1.上传前 上传前选择好要将文件或文件夹上传到远程FTP服务器的哪个目的目录下. 2.上传中 添加上传任务 上传任务完成进度显示 3.上传完成 ============== ...

  5. 分享一个js生成二维码的库

    二维码用js生成会比用服务器生成方便很多,只要把window.location.href的值传入,即可生成对应的二维码..最主要是,这个库可以兼容ie6~ie9哦... 具体使用,请看官网:http: ...

  6. DESTOON系统文章模块默认设置第一张图片为标题图的方法

    连上FTP或者其他方法打开网站目录下的\module\article\admin\template\edit.tpl.php修改设置内容第 <input name="post[thum ...

  7. RichTextBox控件日常使用集合

    1.RichTextBox控件自动滚动到底部 richTextBox1.ScrollToCaret(); //将控件的内容滚动到当前光标位置

  8. github三大步骤

    1)git init : 初始化当前目录,把这个目录变成Git可以管理的目录 2)git add [文件名称]:  把文件添加到仓库 3)git commit -m "对当前提交文件的描述& ...

  9. LeetCode_Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  10. simulate windows postmessage or keydown

    2 ways: 1. under TForm:   if assigned(focused) then      Focused.keydown(key,keychar,[]); 2. using s ...