2012-12-04 15:38 775人阅读 评论(0) 收藏 举报
  1. float angle = 360 / 6;
  2. for (int i = 0; i < 6; i++) {
  3. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  4. float offsetAngle = angle * i;
  5. button.bounds = CGRectMake(0, 0, 32, 32);
  6. button.center = CGPointMake(cos(offsetAngle * RADIANS) * 160, sin(offsetAngle * RADIANS) * 160);
  7. button.tag = i;
  8. CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  9. CGMutablePathRef path = CGPathCreateMutable();
  10. pathAnimation.calculationMode = kCAAnimationPaced;
  11. pathAnimation.fillMode = kCAFillModeForwards;
  12. pathAnimation.removedOnCompletion = NO;
  13. pathAnimation.duration = 2;
  14. CGPathMoveToPoint(path, NULL, button.center.x, button.center.y);
  15. CGPathAddArc(path, NULL, 0, 0, 160, offsetAngle * M_PI/180, offsetAngle * M_PI/180 + M_PI, YES);
  16. pathAnimation.path = path;
  17. CGPathRelease(path);
  18. [button.layer addAnimation:pathAnimation forKey:@"curve"];
  19. [tabBarView addSubview:button];
  20. }

因为只是Layer的内容发生的位置变化,其实UIView还是在原来的位置上,如果需要使用应该在Animation结束后重新设定UIView的位置.

顺便翻译一下原文:

CGPathAddArc (

CGMutablePathRef path,

const CGAffineTransform *m,

CGFloat x,

CGFloat y,

CGFloat radius,

CGFloat startAngle,

CGFloat endAngle,

bool clockwise

);

path:动画的路径;

m:layer的transform;

x:其实x和y是什么我还没弄明白,根据原文应该是弧的圆心点,但我设置过,这更像是偏移量;

y:同上;

startAngle:起始的角度点,零度是与x轴相交点,度数为顺时针;

endAngle:结束的角度点;

clockwis:是否顺时针.

CGPathAddArc的更多相关文章

  1. iOS绘制收益柱状图

    项目需求,参考了其他绘图demo,自己绘制出来了,不过代码改得有点乱,添加了很多变量,时间关系没用太合适的命名,逻辑处理也没进行优化. 看看效果图(虚线区域都是画的,其他区域添加的都是控件),附上源码 ...

  2. iOS CoreAnimation详解(一) 有关Layer的动画

    以前由于项目需要 也写了一些动画 ,但是知识不系统,很散.这段时间趁着项目完成的空袭,来跟着大神的脚步系统的总结一下iOS中Core Animation的知识点. 原博客地址:http://blog. ...

  3. iOS CALayer应用详解(2)

    参考博客:http://blog.csdn.net/hello_hwc?viewmode=list 如果你对CALayer 还没有一个清晰的理解,欢迎看一下前面的博客: http://www.cnbl ...

  4. iOS开发CoreGraphics核心图形框架之一——CGPath的应用

    一.引言    CoreGraphics核心图形框架相较于UIKit框架更加偏于底层.在Objective-C工程中,CoreGraphics其中方法都是采用C语言风格进行编写的,同时其并不支持Obj ...

  5. Quartz2D 编程指南(一)概览、图形上下文、路径、颜色与颜色空间

    概览 图形上下文 路径 颜色与颜色空间 变换 图案 阴影 渐变 透明层 Quartz 2D 中的数据管理 位图与图像遮罩 CoreGraphics 绘制 Layer 0.说明 本篇博客主要是对官方文档 ...

  6. Paths_Quartz2D

    Paths中的几个重要元素 Points void CGContextMoveToPoint (    CGContextRef c,    CGFloat x,    CGFloat y ); 指定 ...

  7. ArrowLayer : A coustom layer animation

    Since my other answer (animating two levels of masks) has some graphics glitches, I decided to try r ...

  8. Paths(转载)

    Paths中的几个重要元素 Points void CGContextMoveToPoint ( CGContextRef c, CGFloat x, CGFloat y ); 指定一个点成为curr ...

  9. 用CAKeyframeAnimation构建动画路径

    复杂路径的动画,我们可以借助关键关键帧动画(CAKeyframeAnimation)来实现,给其的path属性设置相应的路径信息即可. 以下为一个红色的小球按照指定的路径运动的动画. 此动画关键在于如 ...

随机推荐

  1. 【转】jenkins上配置robotframeworkride自动化脚本任务

    jenkins上配置robotframeworkride自动化脚本任务 编写好的自动化脚本,集成在jenkins上进行自动运行于监控,这里采用分布式构建,在一台slave上进行任务构建与自动化脚本的运 ...

  2. linuxmint17.3提示flash不是最新版本解决方法(copy)

    [资料来自于:http://blog.csdn.net/kh896424665/article/details/54879608] 问题:播放视频提示:Adobe Flash Player 不是最新版 ...

  3. ==和equals()的不同点

    两者都可以用于对象的比较."=="用于比较两个对象的内存地址值(引用值)是否相等,equals()方法用于比较两个对象的内容是否一致. String str1 = new Stri ...

  4. POJ2800:Joseph's Problem(等差数列)

    传送门 题意 计算 \(\sum_{i=1}^n(kmodi)\) 分析 1.n>k 直接输出k*(n-k) 2.n<=k 我们发现k/i相同的k%i构成一个等差数列,那么我们从k/i-& ...

  5. js 调试方法两种

    JS的错误捕获一般有下面两种方式: 1. 异常捕获常用方法是 try/catch/ throw /finally 2. 全局捕获window.onerror 1. try/catch/throw/fi ...

  6. 由 var str = 'hello world' str.attr ='666'; 到包装类型

    近期有些小伙伴在公司的一道面试题踩了坑,  今天特地跟大家一起分享下: 原题如下: var str = 'hello world'; str.attr = '666'; console.log(str ...

  7. 从零开始通过idea插件将一个spring boot项目部署到docker容器里运行

    实操:将一个spring boot项目部署到docker容器里运行 实验需要的环境: 腾讯云+Ubuntu 16.04 x64+idea+插件docker integration+daocloud 第 ...

  8. [POI2007]石头花园SKA

    Description Blue Mary是一个有名的石头收藏家.迄今为止,他把他的藏品全部放在他的宫殿的地窖中.现在,他想将他的藏品陈列在他的花园中.皇家花园是一个边长为1000000000单位的平 ...

  9. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  10. Android内存堆上限Android的缺省值是16M(某些机型是24M)

    转自: http://www.cnblogs.com/jacktu/archive/2010/12/30/1921475.html 大家都知道Android的上层应用是基于 Dalvik Virtua ...