国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS漸變圓環旋轉動畫CAShapeLayer CAGradientLayer

2020-07-26 03:13:40
字體:
來源:轉載
供稿:網友

iOS漸變圓環旋轉動畫CAShapeLayer CAGradientLayer

shape.gif

demo.png

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CALayer *layer = [CALayer layer]; layer.backgroundColor = [UIColor redColor].CGColor; //圓環底色 layer.frame = CGRectMake(100, 100, 110, 110); //創建一個圓環 UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(55, 55) radius:50 startAngle:0 endAngle:M_PI*2 clockwise:YES]; //圓環遮罩 CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.fillColor = [UIColor clearColor].CGColor; shapeLayer.strokeColor = [UIColor redColor].CGColor; shapeLayer.lineWidth = 5; shapeLayer.strokeStart = 0; shapeLayer.strokeEnd = 0.8; shapeLayer.lineCap = @"round"; shapeLayer.lineDashPhase = 0.8; shapeLayer.path = bezierPath.CGPath; //顏色漸變 NSMutableArray *colors = [NSMutableArray arrayWithObjects:(id)[UIColor redColor].CGColor,(id)[UIColor whiteColor].CGColor, nil]; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.shadowPath = bezierPath.CGPath; gradientLayer.frame = CGRectMake(50, 50, 60, 60); gradientLayer.startPoint = CGPointMake(0, 1); gradientLayer.endPoint = CGPointMake(1, 0); [gradientLayer setColors:[NSArray arrayWithArray:colors]]; [layer addSublayer:gradientLayer]; //設置顏色漸變 [layer setMask:shapeLayer]; //設置圓環遮罩 [self.view.layer addSublayer:layer]; //動畫 CABasicAnimation *scaleAnimation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; scaleAnimation1.fromValue = [NSNumber numberWithFloat:1.0]; scaleAnimation1.toValue = [NSNumber numberWithFloat:1.5]; scaleAnimation1.autoreverses = YES;// scaleAnimation1.fillMode = kCAFillModeForwards; scaleAnimation1.duration = 0.8; CABasicAnimation *rotationAnimation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation2.fromValue = [NSNumber numberWithFloat:0]; rotationAnimation2.toValue = [NSNumber numberWithFloat:6.0*M_PI]; rotationAnimation2.autoreverses = YES;// scaleAnimation.fillMode = kCAFillModeForwards; rotationAnimation2.repeatCount = MAXFLOAT; rotationAnimation2.beginTime = 0.8; //延時執行,注釋掉動畫會同時進行 rotationAnimation2.duration = 2; //組合動畫 CAAnimationGroup *groupAnnimation = [CAAnimationGroup animation]; groupAnnimation.duration = 4; groupAnnimation.autoreverses = YES; groupAnnimation.animations = @[scaleAnimation1, rotationAnimation2]; groupAnnimation.repeatCount = MAXFLOAT; [layer addAnimation:groupAnnimation forKey:@"groupAnnimation"];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end

關鍵的地方在于CABasicAnimation對象的初始化方式中keyPath的設定。在iOS中有以下幾種不同的keyPath,代表著不同的效果:

以上就是iOS漸變圓環旋轉動畫 的資料整理,后續繼續補充相關資料,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 敦煌市| 北海市| 宜都市| 台中县| 长宁区| 岳西县| 阿拉善左旗| 星子县| 宝坻区| 曲阜市| 香港| 汉沽区| 盐亭县| 遂昌县| 济源市| 天等县| 普宁市| 开平市| 射阳县| 温泉县| 怀宁县| 维西| 应城市| 富源县| 公主岭市| 张家口市| 家居| 徐汇区| 陆河县| 托里县| 大安市| 将乐县| 凯里市| 岗巴县| 定西市| 绥滨县| 中西区| 宣城市| 紫阳县| 五常市| 邓州市|