贝塞尔结合CAShapeLayer绘制路线,CABasicAnimation实现的小动画
来源:互联网 发布:淘淘居淘宝小号 编辑:程序博客网 时间:2024/06/15 23:52
最近项目需求,做的一个标识正在直播的小动画,代码如下:
#import "YGIsOnLiveAnmationView.h"
@interface YGIsOnLiveAnmationView ()
@property (strong, nonatomic) CAShapeLayer * progressLayer;
@property (strong, nonatomic) CAShapeLayer * triangleLayer;
@property (strong, nonatomic) CABasicAnimation *rotateAnimation;
@property (assign, nonatomic) CGFloat progressLineWidth;
@property (strong, nonatomic) UIColor * progressLineColor;
@end
@implementation YGIsOnLiveAnmationView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame lineWidth:(CGFloat)lineWidth lineColor:(UIColor *)lineColor {
self = [self initWithFrame:frame];
if (self) {
self.progressLineWidth = lineWidth;
self.progressLineColor = lineColor;
[self.layer addSublayer:self.progressLayer];
[self.layer addSublayer:self.triangleLayer];
}
return self;
}
- (void)startProgressAnimation {
[self.progressLayer addAnimation:self.rotateAnimation forKey:@"group"];
}
//画三角形
- (CAShapeLayer *)triangleLayer {
if (!_triangleLayer) {
_triangleLayer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPath];
CGFloat X = self.center.x;
CGFloat Y = self.center.y;
[path moveToPoint :CGPointMake(X-3, Y-5)];
[path addLineToPoint:CGPointMake(X-3, Y+5)];
[path addLineToPoint:CGPointMake(X+5, Y)];
[path closePath];
[self.progressLineColor setFill];
[path fill];
_triangleLayer.path = path.CGPath;
}
return _triangleLayer;
}
//画进度
- (CAShapeLayer *)progressLayer {
if (!_progressLayer) {
_progressLayer = [CAShapeLayer layer];
CGFloat width = CGRectGetWidth(self.frame);
CGFloat height = CGRectGetHeight(self.frame);
_progressLayer.frame = CGRectMake(0, 0, width, height);
_progressLayer.position = CGPointMake(width/2.0,height/2.0);
UIBezierPath *aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(width/2.0, height/2.0)
radius:(width - self.progressLineWidth)/2.0
startAngle:0
endAngle:M_PI_4 * 7
clockwise:YES];
[aPath stroke];
_progressLayer.path = aPath.CGPath;
_progressLayer.fillColor = [UIColor clearColor].CGColor;
_progressLayer.lineWidth = self.progressLineWidth;
_progressLayer.strokeColor = self.progressLineColor.CGColor;
_progressLayer.lineCap = kCALineCapRound;
}
return _progressLayer;
}
- (CABasicAnimation *)rotateAnimation {
if (!_rotateAnimation) {
_rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
_rotateAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
_rotateAnimation.toValue = @(M_PI * 2);
_rotateAnimation.fromValue = @(0);
_rotateAnimation.duration = 1;
_rotateAnimation.removedOnCompletion = NO;
_rotateAnimation.repeatCount = FLT_MAX;
}
return _rotateAnimation;
}
@end
- 贝塞尔结合CAShapeLayer绘制路线,CABasicAnimation实现的小动画
- swift 绘制、动画基础 (CAShapeLayer、CABasicAnimation)
- 仿支付宝的付款转圈动画---CAShapeLayer、UIBezierPath、CABasicAnimation
- UIBezierPath和CAShapeLayer结合绘制任意弧度的圆形(包含旋转动画)
- iOS动画详解 (CABasicAnimation,UIBezierPath,CAShapeLayer)
- CAShapeLayer 与CABasicAnimation结合使用时strokeStart、strokeEnd 与fromValue、toValue的用法
- CAShapeLayer的贝塞尔路径动画
- CAShapeLayer + UIBezierPath结合动画效果
- iOS 使用UIBezierPath, CAShapeLayer, CABasicAnimation动态绘制折线
- 用CABasicAnimation实现简单的动画效果
- CAShapeLayer的绘制
- CABasicAnimation动画的解析
- CABasicAnimation动画的使用
- IOS_ UIBezierPath + CABasicAnimation + CAShapeLayer
- iOS 贝塞尔曲线和CAShapeLayer 结合使用的进度条详解
- iOS --用CABasicAnimation实现简单的动画效果
- 使用CABasicAnimation实现的动画效果(一)
- 【iOS开发-动画】CABasicAnimation实现动画
- Opencv 矩阵基础
- 依然思路之hashmap源代码
- Python Socket 编程:聊天室示例程序
- 【测试开发面试】阿里二面
- 【Java并发编程】之一:可重入内置锁 (r)
- 贝塞尔结合CAShapeLayer绘制路线,CABasicAnimation实现的小动画
- 大端模式和小端模式
- kvc kvo
- node.js 调试工具 node-inspector
- 动画说明 李明杰新浪博客
- Js中Prototype、__proto__、Constructor、Object、Function关系介绍
- 初学者之小甲鱼C++运算符重载
- linux下redis的多实例安装配置
- 如何写出低碳环保的Android代码