CAShapeLayer 跟 UIBezierPath 进行动画绘图
来源:互联网 发布:mcgs组态软件视频教程 编辑:程序博客网 时间:2024/05/22 11:34
CAShapeLayer在初始化时也需要给一个frame值,但是,它本身没有形状,它的形状来源于你给定的一个path,然后它去取CGPath值,它与CALayer有着很大的区别
CAShapeLayer有着几点很重要:
1. 它依附于一个给定的path,必须给与path,而且,即使path不完整也会自动首尾相接
2. strokeStart以及strokeEnd代表着在这个path中所占用的百分比
3. CAShapeLayer动画仅仅限于沿着边缘的动画效果,它实现不了填充效果
给定一个指定的Path:
/ // 贝塞尔曲线(创建一个圆) UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100 / 2.f, 100 / 2.f) radius:50 startAngle:0 endAngle:M_PI * 2 clockwise:YES];可以使用UIBezierPath 绘画出其它的图形 。
// 创建一个shapeLayer CAShapeLayer *layer = [CAShapeLayer layer]; // layer.frame = self.bounds; // 与showView的frame一致 layer.strokeColor = [UIColor greenColor].CGColor; // 边缘线的颜色 layer.fillColor = [UIColor clearColor].CGColor; // 闭环填充的颜色 layer.lineCap = kCALineCapRound; // 边缘线的类型 layer.path = path.CGPath; // 从贝塞尔曲线获取到形状 layer.lineWidth = 3; // 线条宽度 layer.strokeEnd = 0.0; // 将layer添加进图层 [self.layer addSublayer:layer];
设置动画使用 strokeEnd 属性
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation.duration = 1.0; pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; pathAnimation.repeatCount=INT32_MAX; pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; pathAnimation.toValue = [NSNumber numberWithFloat:1.0f]; [layer addAnimation:pathAnimation forKey:nil]; layer.strokeEnd = 1;
0 0
- CAShapeLayer 跟 UIBezierPath 进行动画绘图
- iOS CAShapeLayer和UIBezierPath绘图
- CAShapeLayer + UIBezierPath结合动画效果
- iOS动画详解 (CABasicAnimation,UIBezierPath,CAShapeLayer)
- CAShapeLayer UIBezierPath
- 仿支付宝的付款转圈动画---CAShapeLayer、UIBezierPath、CABasicAnimation
- 第三十八篇:CAKeyframeAnimation--+CAShapeLayer+UIBezierPath用法,关键帧动画
- CAShapeLayer与UIBezierPath
- UIBezierPath和CAShapeLayer简介
- 使用CAShapeLayer与UIBezierPath
- CAShapeLayer与UIBezierPath
- CAShapeLayer与UIBezierPath
- CAShapeLayer和UIBezierPath
- ios CAShapeLayer和UIBezierPath
- CAShapeLayer + UIBezierPath = sectionView
- IOS_ UIBezierPath + CABasicAnimation + CAShapeLayer
- CAShapeLayer与UIBezierPath
- iOS绘图系列六:利用CAShapeLayer和UIBezierPath或者CGPath绘制想要的图像
- mongoDB使用
- 关于ngx的一些常用函数和结构体
- CentOS下/etc/sysconfig/下找不到iptables文件
- Swift中出现“no such module cocoa”的错误
- centos6.5下如何安装SVN同时配置多个版本库
- CAShapeLayer 跟 UIBezierPath 进行动画绘图
- C++函数返回局部变量指针的问题
- Linux vim编辑器的批量注释
- RevitAPI: Rebar.CreateFromCurves抛出异常: Unable to create a RebarShape based on the given curves
- 构造方法和析构方法
- ThreadLocal
- Android延时加载两种方式
- cocos2dx 读取json及解析
- asp.net--TextBox属性全研究