iOS 圓的放大動畫效果

來源:互聯網
上載者:User

標籤:

第一步:建立一個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); //繪製路徑}

 

iOS 圓的放大動畫效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.