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的话就是完全绘制。
        
    }
  • 相关阅读:
    iPhone应用程序开发基础之一: IBOutlet与IBAction
    Swift实战-小QQ(第1章):QQ登录界面
    Swift实战-QQ在线音乐(AppleWatch版)
    iOS苹果官方Demo合集
    Git--Submodule使用
    线程审查生产者和消费者
    Lichee(三) Android4.0该产品的目标文件夹,Lichee链接---extract-bsp
    curl转让query string逃生参数
    ERROR 2003 (HY000): Can't connect to MySQL server on '10.16.115.101' (111)
    吐槽一下Activiti用户手册和一本书
  • 原文地址:https://www.cnblogs.com/xiaomingtongxue/p/4518441.html
Copyright © 2011-2022 走看看