关于CAShapeLayer的一些基本操作
2024-09-05 05:45:05
设置圆形进度条:
实现效果如下:
实现代码如下:(注释很详细啦!!!)
UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
shapeView.backgroundColor = [UIColor greenColor];
[self.view addSubview:circleView]; // 实现圆形进度条 CAShapeLayer *shapeLayer =[CAShapeLayer layer];
shapeLayer.frame = circleView.bounds;
//绘制
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:circleView.bounds];
shapeLayer.path = path.CGPath;
// 设置填充颜色
shapeLayer.fillColor = [UIColor greenColor].CGColor;
// 设置线条宽度
shapeLayer.lineWidth = 2.0f;
// 设置线条颜色
shapeLayer.strokeColor = [UIColor redColor].CGColor;
[circleView.layer addSublayer:shapeLayer]; // 设置基础动画
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration = 3.0;
pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
[shapeLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
最后记录一个警告的意思和处理方法:
如果出现上面的这警告问题,原因是:
这个往往是复制网上的带格式的代码导致的。
解决办法:
在提示的地方进行换行处理,首先先选中提示的"_".然后按回车键即可。
最好的方法还是自己敲代码比较合适,不复制就不会出现这些警告啦!!!!
最新文章
- 异步Socket 客户端部分
- redis数据结构存储Linked List设计细节(redis的设计与实现笔记)
- SQL Server 连接超时案例一则
- oracle自定义判断数据是否为数值函数
- Unity逻辑热更新
- Echarts 页面多图自适应的解决办法 (转)
- php +html5 websocket 聊天室
- USB HID usage table
- 【转】SQL Server 2012 配置AlwaysOn(三)
- Nexus 5完全拆解
- VB6.0数据库开发五个实例——罗列的总结
- Wireshark网络抓包(一)——数据包、着色规则和提示
- 【HotSpot】 jps
- 使用handler倒计时
- BZOJ3524[Poi2014]Couriers——主席树
- tigervnc-server安装使用
- springMVC和json整合配置方法
- 使用 spring-boot-devtools 进行热部署
- Springfox与swagger的整合使用(十七)
- Microsoft ReportViewer 控件类型版本兼容问题及解决方法
热门文章
- Maven 发布项目到Jetty服务器———5
- mongodb索引 多健索引
- 2018-2019 XIX Open Cup, Grand Prix of Korea B - Dev, Please Add This!
- nginx中ngx_http_core_module模块
- 记一次k8s服务504 timeout
- HDU 6134 Battlestation Operational | 2017 Multi-University Training Contest 8
- pyinstaller打包程序包含openpyxl库问题解决
- Java中通过Array.sort()对数组从大到小排序
- Material icons 全图标一览
- vue中修改第三方组件的样式不生效