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 ...
随机推荐
- centos上如何安装redis?|centos傻瓜式安装redis教程
本文介绍centos安装redis,请不要安装2.4.3,是有问题的. 首先安装gcc yum -y install gcc yum -y install gcc-c++ yum install ma ...
- servlet 上传文件 参数中文乱码
获取数据时需要进行转码 item.getString("网站使用编码utf-8,GBK等");
- Python学习笔记——迭代器(RandSeq和AnyIter)
1.RandSeq #coding:utf-8 #!/usr/bin/env python 'randSeq.py -- 迭代' #从random模块里仅仅导入choice方法 from random ...
- ubuntu/var/log/下各个日志文件
ubuntu/var/log/下各个日志文件 本文简单介绍ubuntu/var/log/下各个日志文件,方便出现错误的时候查询相应的log /var/log/alternatives.log-更新 ...
- Node.js Stream-基础篇
Node.js Stream - 基础篇 邹斌 ·2016-07-08 11:51 背景 在构建较复杂的系统时,通常将其拆解为功能独立的若干部分.这些部分的接口遵循一定的规范,通过某种方式相连,以共同 ...
- ASCII码表
ASCII码表 ASCII码大致可以分作三部分組成. 第一部分是:ASCII码非打印控制字符: 第二部分是:ASCII码打印字符: 第三部分是:扩展ASCII码打印字符. 第一部分:ASCII非打印控 ...
- hzwer模拟赛 虫洞
[题目描述] N个虫洞,M条单向跃迁路径.从一个虫洞沿跃迁路径到另一个虫洞需要消耗一定量的燃料和1单位时间.虫洞有白洞和黑洞之分.设一条跃迁路径两端的虫洞质量差为delta. 1.从白洞跃迁到黑洞,消 ...
- JSP动作元素之include
采用include指令导入的页面输入静态导入,采用<jsp:include-/>指令属于动态导入. 语法格式如下: <jsp:include page="{relative ...
- Android Activity的加载的模式
---恢复内容开始--- 本文来自http://www.cnblogs.com/lwbqqyumidi/p/3771542.html launchMode在多个Activity跳转的过程中扮演着重要的 ...
- Cookie使用时需要注意个数及大小限制
各浏览器对Cookie有一定的限制,在使用时需要格外注意. 各浏览器之间对cookie的不同限制: IE6.0 IE7.0/8.0/9.0+ Opera FF Safari Chrome cook ...