zoukankan      html  css  js  c++  java
  • iOS 圆的放大动画效果

    第一步:创建一个View,将这个View添加到当前的控制器

    如:

    CGFloat timeW = self.view.bounds.size.width;
    timeAnimation * timean = [[timeAnimation alloc]initWithFrame:CGRectMake(0,0,timeW,timeW)];
         timean.center = CGPointMake(self.view.bounds.size.width*0.5, self.view.bounds.size.height *0.5);
    [self.view addSubview:timean];

    第二步:在View的.m文件中添加如下代码

    #define PI 3.14159265358979323846

    #define kradius self.bounds.size.width*0.1

    -(instancetype)initWithFrame:(CGRect)frame
    {
        if (self = [super initWithFrame:frame]) {
            self.frame = frame;
            self.backgroundColor = [UIColor clearColor];
        }
        return self;
    }
    - (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        
        [self greenRound:context];
        self.alpha = 0.5;
        [self test];
    }
    -(void)test
    {
        // 2.创建缩放动画对象
        CABasicAnimation *scale = [CABasicAnimation animation];
        scale.keyPath = @"transform.scale";
        scale.fromValue =[NSNumber numberWithFloat:0.0];
        scale.toValue =[NSNumber numberWithFloat:1.0];
        CABasicAnimation *scale1 = [CABasicAnimation animation];
        scale1.keyPath = @"opacity";
        scale1.fromValue =[NSNumber numberWithFloat:1.0];
        scale1.toValue =[NSNumber numberWithFloat:0.0];
        // 4.将所有的动画添加到动画组中
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.animations = @[scale,scale1];
        group.duration =.6;
        group.repeatCount = HUGE_VALF;
        group.removedOnCompletion = NO;
        group.fillMode = kCAFillModeForwards;
        [self.layer addAnimation:group forKey:nil];
    }
    /**画绿色的圆*/
    -(void)greenRound:(CGContextRef)context
    {
        CGContextSetRGBStrokeColor(context, 33/255.0, 177/255.0, 75/255.0, 1);//画笔线的颜色
        CGContextSetLineWidth(context, 4.0);//线的宽度
        // x,y为圆点坐标,radius半径,startAngle为开始的弧度,endAngle为 结束的弧度,clockwise 0为顺时针,1为逆时针。
        CGContextAddArc(context, self.bounds.size.width *0.5,self.bounds.size.height*0.5,self.bounds.size.width*0.21, 0, 2*PI, 0); //添加一个圆
        CGContextDrawPath(context, kCGPathStroke); //绘制路径
    }
  • 相关阅读:
    eclipse安装插件(具体过程省略)
    Linux权限
    Anaconda + python环境搭建
    Hadoop的shell命令
    安装Hadoop(单机)
    CentOS 7安装jdk
    Linux文档内容操作
    EOJ 3 玩具谜题
    [转载]基础算法——筛法求素数
    EOJ 3213 向右看齐
  • 原文地址:https://www.cnblogs.com/WX95/p/4729320.html
Copyright © 2011-2022 走看看