博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 圆的放大动画效果
阅读量:4624 次
发布时间:2019-06-09

本文共 1967 字,大约阅读时间需要 6 分钟。

第一步:创建一个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); //绘制路径}

 

转载于:https://www.cnblogs.com/WX95/p/4729320.html

你可能感兴趣的文章
selenium入门环境之浏览器问题
查看>>
BA--三相异步电机_星三角降压启动
查看>>
VM虚拟机安装后的网络设置
查看>>
jQuery Alert Dialogs (Alert, Confirm, & Prompt代替方案)
查看>>
牛客 109 C 操作数 (组合数学)
查看>>
Linux下通过 rm -f 删除大量文件时报错:Argument list too long
查看>>
【2019/2/1】安卓应用——记账本,学习记录【1】
查看>>
记因PHP的内存溢出导致的事故之解决
查看>>
[转]Apache commons 工具包应用
查看>>
Bridge模式——设计模式学习笔记
查看>>
【python】统一转换日期格式dateutil.parser.parse
查看>>
spring的依赖注入
查看>>
CF 576A 猜数
查看>>
『重构--改善既有代码的设计』读书笔记----代码坏味道【3】
查看>>
ABAP 中JSON格式的转换与解析
查看>>
使用oschina的gitserver
查看>>
嵌入式课程学习大纲分享,零基础入门嵌入式技术
查看>>
Could not get the value for parameter encoding for plugin execution default- resources
查看>>
Android 网络通信之Socket
查看>>
python 运维自动化之路 Day3
查看>>