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     

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

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

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

    解决办法:

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

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

  • 相关阅读:
    传统IO总结
    关于JAVA垃圾回收的一些小tips
    一个爬喜马拉雅音频的例子
    return研究
    Java基础知识-java.util.concurrent包下常见类的使用
    <a>链接的四个伪类顺序
    前端面试题
    setTimeout的作用以及setTimeout延时0毫秒的作用
    闭包的使用
    JavaScript typeof obj === ‘object’ 这样写有什么问题
  • 原文地址:https://www.cnblogs.com/pengsi/p/5662646.html
Copyright © 2011-2022 走看看