iOS_SN_push/pop转场动画封装和一般动画封装
封装类中的方法:
#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转场动画封装和一般动画封装的更多相关文章
- UIKit封装的系统动画
简介 在UIKit中,对UIView封装了很多类方法来进行简单的动画实现,在动画过程中,通过对属性值的修改来完成一系列的效果. 在IOS4以前,主要通过 + beginAnimation + setA ...
- uiview封装的基本动画
基本动画的类型为 基本动画的节奏 UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default UIViewAn ...
- 第一百四十二节,JavaScript,封装库--运动动画和透明度动画
JavaScript,封装库--运动动画和透明度动画 /** yi_dong_tou_ming()方法,说明 * * yi_dong_tou_ming()方法,将一个元素,进行一下动画操作 * 1,x ...
- JS---案例:手风琴 (利用封装好的动画函数)
案例:手风琴 封装好的动画函数在common.js里面 //function getStyle(element, attr) {...} //function animate( ...
- 【Flutter 实战】动画序列、共享动画、路由动画
老孟导读:此篇文章是 Flutter 动画系列文章第四篇,本文介绍动画序列.共享动画.路由动画. 动画序列 Flutter中组合动画使用Interval,Interval继承自Curve,用法如下: ...
- iOS动画篇:UIView动画
iOS的动画效果一直都很棒很,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,对于简单的应用场景,我们可以使用UIKit提供的动画来实现. UIView动画 ...
- IOS 动画专题 --iOS核心动画
iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...
- iOS动画篇:核心动画
转:http://www.cocoachina.com/ios/20160517/16290.html 基本概念 1.什么是核心动画 Core Animation(核心动画)是一组功能强大.效果华丽的 ...
- jQuery-1.9.1源码分析系列(十五) 动画处理——缓动动画核心Tween
在jQuery内部函数Animation中调用到了createTweens()来创建缓动动画组,创建完成后的结果为: 可以看到上面的缓动动画组有四个原子动画组成.每一个原子动画的信息都包含在里面了. ...
随机推荐
- WebBrowser.ExecWB方法
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 3 windows环境与shell交互操作
/** * 由SshConfig配置获取一个Session * @param conf * @return */ public static Session createSession(SshConf ...
- Linux 下安装python软件包
1.安装setuptools 下载地址:https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py 解压: tar zxvf set ...
- 《Hadoop权威》学习笔记四:Hadoop的I/O
一.数据完整性 二.压缩 三.序列化 基本概念 序列化指的是将结构化对象转化为字节流以便于通过网络进行传输或写入持久化存储的过程 反序列化指的是将字节流转为一系列结构化对象的过程. 进程间通信 ...
- MediaWiki基本设置
1.左侧导航栏设置 在右上角搜索栏中输入“mediawiki:sidebar” 确认后进行编辑(需要以站长或管理员身份登录). 格式: *导航栏名称一 **链接一地址|链接一名称 **链接二地址|链接 ...
- php基础之三 数组
一.正则表达式: 1. "/"代表界定符, "^"代表开始符号 "&"结束符号 eg: $reg="/(13[0-9] ...
- 使用PHP解压文件Unzip
这是一个非常方便的PHP函数从.zip文件解压缩文件.它有两个参数:第一个是压缩文件的路径和第二 function unzip_file($file, $destination) { // creat ...
- ie6兼容性
文本重复Bug 在IE6中,一些隐藏的元素(如注释.display:none;的元素)被包含在一个浮动元素里,就有可能引发文本重复bug.解决办法:给浮动元素添加display:inline;. 躲猫 ...
- DataSet排序
//排序 if (ds != null && ds.Tables.Count > 0) { DataVi ...
- nodejs javascript微信开发
1.当从第三方软件需要分享到微信的时候 需要给授权处理才能获得微信信息 比如 nickname 等昵称图像等 从第三方登陆跳转到微信分享页需要 shareurl = http://open.weixi ...