//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的更多相关文章

  1. IOS中的动画——Core Animation

    一.基础动画 CABasicAnimation //初始化方式 CABasicAnimation * cabase=[CABasicAnimation animation]; //通过keyPath设 ...

  2. iOS 核心动画 Core Animation浅谈

    代码地址如下:http://www.demodashi.com/demo/11603.html 前记 关于实现一个iOS动画,如果简单的,我们可以直接调用UIView的代码块来实现,虽然使用UIVie ...

  3. iOS开发之核心动画(Core Animation)

    1.概述 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对应的框架< ...

  4. (转)iOS动画Core Animation

    文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...

  5. 核心动画——Core Animation

    一. CALayer (一). CALayer简单介绍 在iOS中,你能看得见摸得着的东西基本上都是UIView,比方一个button.一个文本标签.一个文本输入框.一个图标等等.这些都是UIView ...

  6. 动画(Animation) 、 高级动画(Core Animation)

    1 演示UIImage制作的动画 1.1 问题 UIImage动画是IOS提供的最基本的动画,通常用于制作一些小型的动画,本案例使用UIImage制作一个小狗跑动的动画,如图-1所示: 图-1 1.2 ...

  7. &lt;图形图像,动画,多媒体&gt; 读书笔记 --- 音效

    音频多媒体文件主要是存放音频数据信息,音频文件在录制的过程中把声音信号,通过音频编码,变成音频数字信号保存到某种格式文件里.在播放过程中在对音频文件解码,解码出的信号通过扬声器等设备就能够转成音波.音 ...

  8. &lt;图形图像,动画,多媒体&gt; 读书笔记 --- AirPlay

    AirPlay技术是之前一直没有接触过的技术,正好这次做一个笔记 共用: 1.能够通过AirPlay将iOS和MAC设备上的视频或音频输出到高清电视上或高保真音响 2.能够通过AirPlay将iOS和 ...

  9. &lt;图形图像,动画,多媒体&gt; 读书笔记 --- 力学行为特性

    UIKit力学行为包括了:重力(UIGravityBehavior),碰撞(UICollisionBehavior),吸附(UIAttachmentBehavior),推(UIPushBehavior ...

随机推荐

  1. mysql备份脚本,每天执行一次全量备份,三次增量备份

    线上一个小业务的mysql备份 全量备份 #!/bin/bash #crete by hexm at -- #scripte name : full_backup.sh #descriptioni : ...

  2. QQ空间爬虫最新分享,一天 400 万条数据(附代码地址)

    http://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&mid=2653552228&idx=1&sn=e476bf23556406c ...

  3. PDO防sql注入原理分析

    使用pdo的预处理方式可以避免sql注入. 在php手册中'PDO--预处理语句与存储过程'下的说明: 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作是想要运行的 SQL 的 ...

  4. IBatis 2.x 和 MyBatis 3.0.x 的区别(从 iBatis 到 MyBatis)

    从 iBatis 到 MyBatis,你准备好了吗? 对于从事 Java EE 的开发人员来说,iBatis 是一个再熟悉不过的持久层框架了,在 Hibernate.JPA 这样的一站式对象 / 关系 ...

  5. 解决table不能换行的问题与CSS之自动换行总结

    table不能换行问题 一般是:一行里面全是数字或是字母或者结尾有多个感叹号而导致 table不能换行,中文默认的会自动换行的,字母不能换行问题:style="table-layout:fi ...

  6. Linux tar (打包.压缩.解压缩)命令说明 | tar如何解压文件到指定的目录?

    打包举例:将 /usr/local/src/zlib-1.2.5目录下的文件打包成 zlib-1.2.5.tar.gz cd /usr/local/src tar -czvf ./zlib-1.2.5 ...

  7. Marquee 滚动参数

    new marquee("Layer3", 2, 1, 989, 68, 20, 0, 0, 238); 参数说明:Layer3 :容器ID 2 :向上滚动(0向上 1向下 2向左 ...

  8. ubuntu 安装vsftpd服务器 ftp

    http://www.cnblogs.com/likwo/p/3154868.html http://help.aliyun.com/knowledge_detail.htm?knowledgeId= ...

  9. UVALive 4849 String Phone(2-sat、01染色)

    题目一眼看去以为是4-sat... 题意:给n(n<=3000)个黑方块的坐标,保证黑方块没有公共边.对于每个黑方块选一个角作为结点,使得所选结点满足输入的一个无向图.其中距离为曼哈顿距离.输出 ...

  10. poj1988_Cube Stacking

    Cube Stacking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 24130   Accepted: 8468 Ca ...