zoukankan      html  css  js  c++  java
  • 一个扇形的动画效果

    用cashapelayer和core animation实现的一个扇形的动画效果。

    直接贴代码 可以让cashapelayer跟着动画里面的一个path动态的绘图

    -(void)addarcanimation
    {
        CAShapeLayer *linelayer=[CAShapeLayer layer];
        linelayer.strokeColor=[[UIColor colorWithRed:0.400 green:1.000 blue:1.000 alpha:1.000] CGColor];
        linelayer.fillColor=nil;//不能动态填充,你可以试试把设置个颜色,把linewidth设置小一些 看有什么效果。
        linelayer.lineWidth=40.0f;//线条宽度必须设高一点,设低了就是空心的
        linelayer.lineCap=kCALineCapButt;
        [self.view.layer addSublayer:linelayer];
    //把layer插入你需要绘图的layer
        
        float x=self.view.bounds.size.width/2;
        float y=self.totaltimelable.frame.origin.y+self.totaltimelable.frame.size.height+(self.xuanzeLable.frame.origin.y-(self.totaltimelable.frame.origin.y+self.totaltimelable.bounds.size.height))/2;
        
        float radius=(self.xuanzeLable.frame.origin.y-(self.totaltimelable.frame.origin.y+self.totaltimelable.bounds.size.height))/2/2-5;
        
        UIBezierPath *path=[UIBezierPath bezierPathWithArcCenter:CGPointMake(x, y) radius:radius startAngle:0 endAngle:M_PI*2*[self totalworktimeproportionoftotaltime] clockwise:YES];
        
        linelayer.path=path.CGPath;//把layer的path设为动画里尼创建的path 必须是cgpath类型
    
        
        CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        
        animation.duration=1.0f;
        
        animation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
        
        animation.fromValue=[NSNumber numberWithFloat:0.0f];
        
        animation.toValue=[NSNumber numberWithFloat:1.0f];
        
        animation.autoreverses=NO;
        
        animation.fillMode=kCAFillModeForwards;
        
        animation.repeatCount=1;
        
        [linelayer addAnimation:animation forKey:@"strokeEndAnimation"];
        
        linelayer.strokeEnd=1.0f;
        //一定要把strokeEnd是什么搞清楚,它代表了layer的绘制程度,从0到1,0的话就是什么都不绘制,1的话就是完全绘制。
        
    }
  • 相关阅读:
    315. 计算右侧小于当前元素的个数
    55. 跳跃游戏
    <leetcode c++>72. 编辑距离
    "NTLDR is missing"和"NTLDR is compressed"的解决办法
    Windows Live Mail不能发送图片附件的2种解决方法
    【】使用word2010同步更新自己在不同网站的博客
    新浪博客测试
    【】引用 CSS行高line-height属性理解及应用
    "NTLDR is missing"和"NTLDR is compressed"的解决办法
    排序算法-冒泡排序(javascript)
  • 原文地址:https://www.cnblogs.com/xiaomingtongxue/p/4518441.html
Copyright © 2011-2022 走看看