iOS 图形图像动画 Core Animation
//Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self
#define StrongSelf __strong __typeof(weakSelf) self = weakSelf //添加
- (void)add:(id)sender {
[UIView animateWithDuration: animations:^{
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
}];
}
//翻页
- (void)curl:(id)sender { WeakSelf;
[UIView animateWithDuration: animations:^{
StrongSelf;
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}];
}
//移入
- (void)move:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = kCATransitionMoveIn;
trans.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//揭开
- (void)reveal:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = kCATransitionReveal;
trans.subtype = kCATransitionFromTop;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//立方体
- (void)cube:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"cube";
trans.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//收缩
- (void)suck:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"suckEffect";
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//翻转
- (void)oglFlip:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"oglFlip";
trans.subtype = kCATransitionFromBottom;
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
//水波
- (void)ripple:(id)sender {
CATransition *trans = [CATransition animation];
trans.duration = 2.0f;
trans.type = @"rippleEffect";
[self.view.layer addAnimation:trans forKey:@"animation"];
[self.view exchangeSubviewAtIndex: withSubviewAtIndex:];
}
draw default shape
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, );
CGContextSetRGBStrokeColor(ctx, , , , ); //straight line
const CGPoint points1[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points1, ); CGContextSetLineCap(ctx, kCGLineCapSquare);
const CGPoint points2[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points2, ); CGContextSetLineCap(ctx, kCGLineCapRound);
const CGPoint points3[] = {CGPointMake(, ),CGPointMake(, ),CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points3, ); //dashed line
CGContextSetLineCap(ctx, kCGLineCapButt);
CGContextSetLineWidth(ctx, );
CGFloat patterns1[] = {,};
CGContextSetLineDash(ctx, , patterns1, ); const CGPoint points4[] = {CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points4, ); CGContextSetLineDash(ctx, , patterns1, );
const CGPoint points5[] = {CGPointMake(, ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points5, ); CGFloat patterns2[] = {,,,,,,,,,,,,,,,,,};
CGContextSetLineDash(ctx, , patterns2, );
const CGPoint points6[] = {CGPointMake( , ),CGPointMake(, )};
CGContextStrokeLineSegments(ctx, points6, ); //rectangle
CGContextSetStrokeColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextSetFillColorWithColor(ctx, [UIColor blueColor].CGColor);
CGContextSetLineWidth(ctx, );
CGContextSetLineDash(ctx, , , );//cancel dashed style
CGContextStrokeRect(ctx, CGRectMake(, , , )); CGContextSetStrokeColorWithColor(ctx, [UIColor purpleColor].CGColor);
CGContextSetLineJoin(ctx, kCGLineJoinRound);//round corner
CGContextStrokeRect(ctx, CGRectMake(, , , )); CGContextSetRGBStrokeColor(ctx, 1.0, , 1.0, );
CGContextSetLineJoin(ctx, kCGLineJoinBevel);//cliped corner
CGContextStrokeRect(ctx, CGRectMake(, ,, )); CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor);//filled rectangle
CGContextFillRect(ctx, CGRectMake(,, , )); //oval
CGContextSetRGBStrokeColor(ctx, , , , );
CGContextStrokeEllipseInRect(ctx, CGRectMake(, , , ));//Stroke oval CGContextSetRGBFillColor(ctx, , , , );
CGContextFillEllipseInRect(ctx, CGRectMake(, , , ));//Filled oval
draw custom shape
CGContextRef ctx = UIGraphicsGetCurrentContext();//get context
for (int i = ; i < ; i++) {
CGContextBeginPath(ctx);
CGContextAddArc(ctx, i * , i * , (i + ) * , , 1.5 * M_PI, );//actually 0 means clockwise
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , ( - i) * 0.1);
CGContextFillPath(ctx);
}
draw round rect
CGContextRef ctx = UIGraphicsGetCurrentContext();//get context
CGContextBeginPath(ctx);
CGFloat x,y,radius,width,height;
x = ; y = ; radius = ; width = ; height = ;
CGContextMoveToPoint(ctx, x + radius, y);//move to left top corner
CGContextAddLineToPoint(ctx, x + width - radius, y);//add top line to right top corner
CGContextAddArcToPoint(ctx, x + width, y, x + width, y + radius, radius);//add right top corner
CGContextAddLineToPoint(ctx, x + width, y + height - radius);//add right line to right bottom corner
CGContextAddArcToPoint(ctx, x + width, y + height, x + width - radius, y + height, radius);//add right bottom corner
CGContextAddLineToPoint(ctx, x + radius, y + height);//add bottom line to left bottom corner
CGContextAddArcToPoint(ctx, x, y + height, x, y + height - radius, radius);//add left bottom corner
CGContextAddLineToPoint(ctx, x, y + radius);//add left line to left top corner
CGContextAddArcToPoint(ctx, x, y, x + radius, y, radius);//add left top corner
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);
draw nCorner star
CGContextRef ctx = UIGraphicsGetCurrentContext();//get context
CGContextBeginPath(ctx);
CGFloat x,y,size;
NSInteger nCorner = ;//n corner
x = ; y = ; size = ;
CGFloat dig = * M_PI / nCorner;CGContextMoveToPoint(ctx, x, y + size);
for (int i = ; i <= nCorner; i++) {
CGFloat _x = sin(i * dig);
CGFloat _y = cos(i * dig);
CGContextAddLineToPoint(ctx, _x * size + x, _y * size + y);
}
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);
draw flower
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGFloat x,y,size,length;
NSInteger nCorner = ;//n corner
x = ; y = ; size = ; length = ;//length should be bigger
CGContextMoveToPoint(ctx, x, y + size);
CGFloat dig = * M_PI / nCorner;
for (int i = ; i < nCorner + ; i++) {
//count control point
CGFloat ctrlX = sin((i - 0.5) * dig) * length + x;
CGFloat ctrlY = cos((i - 0.5) * dig) * length + y;
//count end point
CGFloat _x = sin(i * dig) * size + x;
CGFloat _y = cos(i * dig) * size + y;
//draw line
CGContextAddQuadCurveToPoint(ctx, ctrlX, ctrlY, _x, _y);
}
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, , , , 0.6);
CGContextFillPath(ctx);
use coordinate
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, , );//move the coordinate
for (int i = ; i < ; i++) {
CGContextSetRGBFillColor(ctx, , , , 0.3 - i * 0.01);
CGContextFillRect(ctx, CGRectMake(, , , ));
CGContextTranslateCTM(ctx, , );
CGContextScaleCTM(ctx, 0.93, 0.93);
CGContextRotateCTM(ctx, - M_PI / );
}
iOS 图形图像动画 Core Animation的更多相关文章
- IOS中的动画——Core Animation
一.基础动画 CABasicAnimation //初始化方式 CABasicAnimation * cabase=[CABasicAnimation animation]; //通过keyPath设 ...
- iOS 核心动画 Core Animation浅谈
代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...
- iOS开发之核心动画(Core Animation)
1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...
- (转)iOS动画Core Animation
文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...
- 核心动画——Core Animation
一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...
- 动画(Animation) 、 高级动画(Core Animation)
1 演示UIImage制作的动画 1.1 问题 UIImage动画是IOS提供的最基本的动画,通常用于制作一些小型的动画,本案例使用UIImage制作一个小狗跑动的动画,如图-1所示: 图-1 1.2 ...
- <图形图像,动画,多媒体> 读书笔记 --- 音效
音频多媒体文件主要是存放音频数据信息,音频文件在录制的过程中把声音信号,通过音频编码,变成音频数字信号保存到某种格式文件里.在播放过程中在对音频文件解码,解码出的信号通过扬声器等设备就能够转成音波.音 ...
- <图形图像,动画,多媒体> 读书笔记 --- AirPlay
AirPlay技术是之前一直没有接触过的技术,正好这次做一个笔记 共用: 1.能够通过AirPlay将iOS和MAC设备上的视频或音频输出到高清电视上或高保真音响 2.能够通过AirPlay将iOS和 ...
- <图形图像,动画,多媒体> 读书笔记 --- 力学行为特性
UIKit力学行为包括了:重力(UIGravityBehavior),碰撞(UICollisionBehavior),吸附(UIAttachmentBehavior),推(UIPushBehavior ...
随机推荐
- Python Day1
一.安装python windows 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装到C盘下 3.配置环境变量 右键计算机属性---高级系统设置 ...
- Java框架--jQueryEasyUI
111------------------------------------------------------------------------------------------------- ...
- iis搭建FTP服务器
win7下如何开启iis请参考前一篇 使用iis并搭建 iis 图片服务器 ftp登陆格式 : ftp://[帐号]:[密码]@[IP]:[端口] ftp://用户名:密码@FTP服务器IP或域名: ...
- 在Application中集成Microsoft Translator服务之翻译语言代码
Microsoft Translator支持多种语言,当我们获取服务时使用这些代码来表示我们是使用哪种语言翻译成什么语言,以下是相关语言对应的代码和中文名 为了方便我已经将数据库上传到云盘上,读者可 ...
- [SQL] SQL学习笔记之基础操作
1 SQL介绍 SQL 是用于访问和处理数据库的标准的计算机语言.关于SQL的具体介绍,我们通过回答如下三个问题来进行. SQL 是什么? SQL,指结构化查询语言,全称是 Structured Qu ...
- BitMap算法应用:Redis队列滤重优化
工作中有用到Redis滤重队列. 原来的方法如下: 方法一 为了保证操作原子性,使用Redis执行Lua脚本. 在脚本中的逻辑是,如果队列不超过某个数值,进行一次lrem操作(队列使用list结构), ...
- mongo副本集搭建及服务器复用方案
比较常见的mongodb副本集搭建是有:常规节点.数据副本.仲裁节点组成,也就是需要三台服务器组建.常规节点即数据的主存储节点,数据副本是主存储节点的从属节点,它定期去主节点获取更新日志来更新自己.仲 ...
- PROJ4初探(转并整理格式)
PROJ4初探(转并整理格式) Proj4是一个免费的GIS工具,软件还称不上. 它专注于地图投影的表达,以及转换.采用一种非常简单明了的投影表达--PROJ4,比其它的投影定义简单,但很明显.很容易 ...
- RF执行顺序
case: 按照定义的上下位置顺序执行,通过Ctrl+上下方向键,来改变执行次序. 包含suite的目录:按字母顺序. suite: 按字母顺序执行.可以加01__xxx.txt这样的前缀来控制顺序.
- 设计模式--单例模式Singleton(创建型)
单例模式很显然是定义一个类,这个类在程序中只有唯一的实例对象.一般单例类的构造函数是私有的,只能通过调用静态函数GetInstance来获取实例. 一.单例模式有三种:懒汉式单例.饿汉式单例.登记式单 ...