zoukankan      html  css  js  c++  java
  • 关于CAShapeLayer的一些基本操作

    设置圆形进度条:

    实现效果如下:

    实现代码如下:(注释很详细啦!!!)

     1  UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(40, 200, 100, 100)];
     2     shapeView.backgroundColor = [UIColor greenColor];
     3     [self.view addSubview:circleView];
     4     
     5     // 实现圆形进度条
     6     
     7     CAShapeLayer *shapeLayer =[CAShapeLayer layer];
     8     shapeLayer.frame = circleView.bounds;
     9     //绘制
    10     UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:circleView.bounds];
    11     shapeLayer.path = path.CGPath;
    12     // 设置填充颜色
    13     shapeLayer.fillColor = [UIColor greenColor].CGColor;
    14     // 设置线条宽度
    15     shapeLayer.lineWidth = 2.0f;
    16     // 设置线条颜色
    17     shapeLayer.strokeColor = [UIColor redColor].CGColor;
    18     [circleView.layer addSublayer:shapeLayer];
    19     
    20     // 设置基础动画
    21     CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    22     pathAnimation.duration = 3.0;
    23     pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    24     pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    25     pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    26     pathAnimation.fillMode = kCAFillModeForwards;
    27     pathAnimation.removedOnCompletion = NO;
    28     [shapeLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];
    29     

    最后记录一个警告的意思和处理方法:

    如果出现上面的这警告问题,原因是:

    这个往往是复制网上的带格式的代码导致的。

    解决办法:

    在提示的地方进行换行处理,首先先选中提示的"_".然后按回车键即可。

    最好的方法还是自己敲代码比较合适,不复制就不会出现这些警告啦!!!!

  • 相关阅读:
    丑数系列
    452. 用最少数量的箭引爆气球
    406. 根据身高重建队列
    763. 划分字母区间
    所有二叉树题目记录
    二叉树前中后序遍历非递归(迭代)解法
    二叉树的层序遍历题目汇总
    442. 数组中重复的数据&&448. 找到所有数组中消失的数字
    225. 用队列实现栈(Easy)
    使用ClosedXML读写excel
  • 原文地址:https://www.cnblogs.com/pengsi/p/5662646.html
Copyright © 2011-2022 走看看