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 ...
 
随机推荐
- 正则表达式之g标志,match和 exec
			
1.g标志 g标志一般是与match和exec来连用,否则g标志没有太大的意义. 先来看一个带g标志的例子: var str = "tankZHang (231144) tank yi ...
 - boost之lexical_cast
			
第一次翻译,虽然是个很简单的函数介绍... 文件boost/lexical_cast.hpp中定义了此函数: namespace boost { class bad_lexical_cast; tem ...
 - EXPLAINING WHAT ACTION AND FUNC ARE
			
http://simpleprogrammer.com/2010/09/24/explaining-what-action-and-func-are/ Explaining What Action A ...
 - SVN和Git下载地址
			
SVN: TortoiseSVN:https://tortoisesvn.net/downloads.html (安装包和语言) Git: Git for Windows:https://git-fo ...
 - 白话讲MyIsam和InnoDB的区别
			
"MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持"这是网上对MyISAM和InnoDB的解释,很抽象吧,我们用白话的方式解释一下其实也比较简单所谓事务处理,就是原 ...
 - POJ2914 (未解决)无向图最小割|Stoer-Wagner算法|模板
			
还不是很懂,贴两篇学习的博客: http://www.hankcs.com/program/algorithm/poj-2914-minimum-cut.html http://blog.sina.c ...
 - 如何给外部引用的js文件传递参数
			
1.定义全局变量 <script language="javascript"> var g = "I'm here"; </script> ...
 - linux常用命令-文件搜索命令-find
			
find [目录] [选项] 文件名或者正则表达式 -name 根据文件名搜索 -iname 搜索文件名的时候忽略大小写 例:find /etc -name init find /etc -i ...
 - jquery 事件委托
			
什么事件委托? DOM在为页面中的每个元素分派事件时,相应的元素一般都在事件冒泡阶段处理事件.在类似 body > div > a 这样的结构中,如果单击a元素,click事件会从a一直冒 ...
 - 常用mysql语句
			
mysql基本知识:日志文件 =======================================开启/关闭日志修改 /etc/my.cnf #log-bin=mysql-bin #重启my ...