• 一个扇形的动画效果


    用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的话就是完全绘制。
        
    }
  • 相关阅读:
    站立会议(2)
    站立会议(1)
    学习进度条
    四则运算2
    学习进度条
    IDEA用maven创建springMVC项目和配置
    Itellij Idea全局搜索
    Spring各个jar包作用
    IDEA一定要改的八条配置
    Nio使用Selector客户端与服务器的通信
  • 原文地址:https://www.cnblogs.com/xiaomingtongxue/p/4518441.html
Copyright © 2020-2023  润新知