//
// ColorView.m
// MulticolorLayerDemo
//
// Created by lance on 14-8-1.
// Copyright (c) 2014年 Liuyu. All rights reserved.
//
#import "ColorView.h"
<img src="https://img-blog.csdn.net/20140801112318109?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGFuY2VfbGFu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" width="480" height="874" alt="" />
@implementation ColorView
+ (Class)layerClass
{
return [CAGradientLayer class];
}
- (id)initWithFrame:(CGRect)frame startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
_startPoint = startPoint;
_endPoint = endPoint;
[self setColorView];
self.layer.mask = [self productCircle];
}
return self;
}
// 生成一张彩照
- (void)setColorView
{
CAGradientLayer *gradientlayer = (id)self.layer;
gradientlayer.startPoint = _startPoint;
gradientlayer.endPoint = _endPoint;
// 颜色
NSMutableArray *colors = [NSMutableArray new];
for (int i = 0; i <= 360; i += 10) {
[colors addObject:(id)[UIColor colorWithHue:1.0 * i / 360.0 saturation:1.0 brightness:1.0 alpha:1.0].CGColor];
}
[gradientlayer setColors:colors];
}
// 画圆
- (CAShapeLayer *)productCircle
{
// 圆的路径
CGPoint centerPoint = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = self.bounds.size.width / 2.0 - 40;
UIBezierPath *bp = [UIBezierPath bezierPathWithArcCenter:centerPoint
radius:radius
startAngle:M_PI
endAngle:-M_PI
clockwise:YES];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = bp.CGPath;
shapeLayer.lineWidth = 2.0;
shapeLayer.strokeColor = [UIColor grayColor].CGColor;
// shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeStart = 0.0;
shapeLayer.strokeEnd = 1.0;
return shapeLayer;
}
- (void)startAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 4.0f;
animation.repeatCount = MAXFLOAT;
animation.fromValue = [NSNumber numberWithFloat:0.0];
animation.toValue = [NSNumber numberWithFloat:M_PI * 2];
[self.layer addAnimation:animation forKey:@"transform"];
}
- (void)endAnimation
{
[self.layer removeAnimationForKey:@"transform"];
}
@end
ios 动画 彩图
最新推荐文章于 2024-06-11 11:44:53 发布