美文网首页
心电图动画

心电图动画

作者: Fendouzhe | 来源:发表于2017-12-11 14:56 被阅读0次

实际效果:


源码(源码没有进行封装,细节都没有处理,望见谅)如下:

#import "LRElectrocardiogramController.h"
#import "UIView+SetRect.h"

#define LayerFrame CGRectMake(0,0,600,300);
#define LineWidth 3.0f;
#define ShadowOpacity 1.0f
#define ShadowRadius 4.0f

@interface LRElectrocardiogramController ()

@end

@implementation LRElectrocardiogramController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    // 界面缩小系数
    CGFloat scale = 1;
    
    if (iPhone4_4s || iPhone5_5s) {
        
        scale = 0.65f;
        
    } else if (iPhone6_6s || iPhoneX_X) {
        
        scale = 0.75f;
        
    } else if (iPhone6_6sPlus) {
        
        scale = 0.8f;
    }
    
    self.view.backgroundColor = [UIColor blackColor];
    //绘制心电图背景
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = LayerFrame;
        shapeLayer.path = [self path].CGPath;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor whiteColor].CGColor;
        shapeLayer.lineWidth = 2.f;
        shapeLayer.opacity = 0.5;
        shapeLayer.position = self.view.center;
        shapeLayer.transform = CATransform3DMakeScale(scale, scale, 1.0f);
        [self.view.layer addSublayer:shapeLayer];
    }
    
    //redColor line
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = LayerFrame;
        shapeLayer.position = self.view.center;
        shapeLayer.path = [self path].CGPath;
        //一开始不展示
        shapeLayer.strokeEnd = 0.f;
        shapeLayer.lineWidth = LineWidth;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor redColor].CGColor;
        shapeLayer.shadowColor = [UIColor redColor].CGColor;
        shapeLayer.shadowRadius = ShadowRadius;
        shapeLayer.shadowOpacity = ShadowOpacity;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.transform = CATransform3DMakeScale(scale, scale, 1.0f);
        [self.view.layer addSublayer:shapeLayer];
        
        CGFloat MAX = 0.98f;//总进度的0.98
        CGFloat GAP = 0.02;//总进度的0.02
        //开始位置
        CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        aniStart.fromValue = @(0);
        aniStart.toValue = @(MAX);
        //结束位置
        CABasicAnimation *aniEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        aniEnd.fromValue = @(GAP);
        aniEnd.toValue = @(MAX+GAP);
        
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.duration = 4.f;
        group.repeatCount = MAXFLOAT;
        group.autoreverses = YES;
        group.animations = @[aniStart,aniEnd];
        
        [shapeLayer addAnimation:group forKey:nil];
        
    }
    
    //greenColor line
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = LayerFrame;
        shapeLayer.position = self.view.center;
        shapeLayer.path = [self path].CGPath;
        shapeLayer.strokeEnd = 0.f;
        shapeLayer.lineWidth = LineWidth;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor greenColor].CGColor;
        shapeLayer.shadowColor = [UIColor greenColor].CGColor;
        shapeLayer.shadowRadius = ShadowRadius;
        shapeLayer.shadowOpacity = ShadowOpacity;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.transform = CATransform3DMakeScale(scale, scale, 1.0f);
        [self.view.layer addSublayer:shapeLayer];
        
        CGFloat MAX = 0.98f;//总进度的0.98
        CGFloat GAP = 0.02;//总进度的0.02
        
        CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        aniStart.fromValue = @0;
        aniStart.toValue = @(MAX);
        
        CABasicAnimation *aniEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        aniEnd.fromValue = @(GAP);
        aniEnd.toValue = @(GAP+MAX);
        
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.duration = 8.f;
        group.repeatCount = MAXFLOAT;
        group.autoreverses = YES;
        group.animations = @[aniStart,aniEnd];
        [shapeLayer addAnimation:group forKey:nil];
        
    }
    
    //yellowColor line
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = LayerFrame;
        shapeLayer.position = self.view.center;
        shapeLayer.path = [self path].CGPath;
        shapeLayer.strokeEnd = 0.f;
        shapeLayer.lineWidth = LineWidth;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor yellowColor].CGColor;
        shapeLayer.shadowColor = [UIColor yellowColor].CGColor;
        shapeLayer.shadowRadius = ShadowRadius;
        shapeLayer.shadowOpacity = ShadowOpacity;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.transform = CATransform3DMakeScale(scale, scale, 1.0f);
        [self.view.layer addSublayer:shapeLayer];
        
        CGFloat MAX = 0.98f;//总进度的0.98
        CGFloat GAP = 0.02;//总进度的0.02
        
        CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        aniStart.fromValue = @(MAX);
        aniStart.toValue = @(0);
        
        CABasicAnimation *aniEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        aniEnd.fromValue = @(GAP+MAX);
        aniEnd.toValue = @(GAP);
        
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.duration = 8.f;
        group.repeatCount = MAXFLOAT;
        group.autoreverses = YES;
        group.animations = @[aniStart,aniEnd];
        [shapeLayer addAnimation:group forKey:nil];
        
    }
    
    //cyanColor line
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame = LayerFrame;
        shapeLayer.position = self.view.center;
        shapeLayer.path = [self path].CGPath;
        shapeLayer.strokeEnd = 0.f;
        shapeLayer.lineWidth = LineWidth;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor cyanColor].CGColor;
        shapeLayer.shadowColor = [UIColor cyanColor].CGColor;
        shapeLayer.shadowRadius = ShadowRadius;
        shapeLayer.shadowOpacity = ShadowOpacity;
        shapeLayer.lineCap = kCALineCapRound;
        shapeLayer.transform = CATransform3DMakeScale(scale, scale, 1.0f);
        [self.view.layer addSublayer:shapeLayer];
        
        CGFloat MAX = 0.98f;//总进度的0.98
        CGFloat GAP = 0.02;//总进度的0.02
        
        CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
        aniStart.fromValue = @(MAX);
        aniStart.toValue = @(0);
        
        CABasicAnimation *aniEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
        aniEnd.fromValue = @(GAP+MAX);
        aniEnd.toValue = @(GAP);
        
        CAAnimationGroup *group = [CAAnimationGroup animation];
        group.duration = 4.f;
        group.repeatCount = MAXFLOAT;
        group.autoreverses = YES;
        group.animations = @[aniStart,aniEnd];
        [shapeLayer addAnimation:group forKey:nil];
        
    }
    
}

- (UIBezierPath *)path {
    
    UIBezierPath* bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint   : CGPointMake(0, 150)];
    [bezierPath addLineToPoint: CGPointMake(68, 150)];
    [bezierPath addLineToPoint: CGPointMake(83, 107)];
    [bezierPath addLineToPoint: CGPointMake(96, 206)];
    [bezierPath addLineToPoint: CGPointMake(102, 150)];
    [bezierPath addLineToPoint: CGPointMake(116, 150)];
    [bezierPath addLineToPoint: CGPointMake(127, 82)];
    [bezierPath addLineToPoint: CGPointMake(143, 213)];
    [bezierPath addLineToPoint: CGPointMake(160, 150)];
    [bezierPath addLineToPoint: CGPointMake(179, 150)];
    [bezierPath addLineToPoint: CGPointMake(183, 135)];
    [bezierPath addLineToPoint: CGPointMake(192, 169)];
    [bezierPath addLineToPoint: CGPointMake(199, 150)];
    [bezierPath addLineToPoint: CGPointMake(210, 177)];
    [bezierPath addLineToPoint: CGPointMake(227, 70)];
    [bezierPath addLineToPoint: CGPointMake(230, 210)];
    [bezierPath addLineToPoint: CGPointMake(249, 135)];
    [bezierPath addLineToPoint: CGPointMake(257, 150)];
    [bezierPath addLineToPoint: CGPointMake(360, 150)];
    [bezierPath addLineToPoint: CGPointMake(372, 124)];
    [bezierPath addLineToPoint: CGPointMake(395, 197)];
    [bezierPath addLineToPoint: CGPointMake(408, 82)];
    [bezierPath addLineToPoint: CGPointMake(416, 150)];
    [bezierPath addLineToPoint: CGPointMake(424, 135)];
    [bezierPath addLineToPoint: CGPointMake(448, 224)];
    [bezierPath addLineToPoint: CGPointMake(456, 107)];
    [bezierPath addLineToPoint: CGPointMake(463, 150)];
    [bezierPath addLineToPoint: CGPointMake(600, 150)];
    return bezierPath;
}

代码上传到github,欢迎下载查看。

相关文章

  • 心电图动画

    实际效果: 源码(源码没有进行封装,细节都没有处理,望见谅)如下: 代码上传到github,欢迎下载查看。

  • 20161117-心电图动画

    游戏动画联想....有点卡顿

  • OC 曲线图表动画 类似心电图

    前一段时间帮朋友写的一个这样的动画。大概效果如图所示,一个类似心电图的动画。该动画是是在以前图表动画的基础上做了适...

  • 入职体检的心电图和动态心电图有什么不一样?

    入职体检的心电图就是我们平时做的常规心电图,而动态心电图一般指的是24小时心电图。两种不同的心电图各有各的用途,在...

  • 心电图

    正常心电图: 1.没刻度的: 2. 有刻度的(临床常用): 纵向每一小格代表0.1mV,横向每一小格代表0.04s...

  • 〖心电图〗

    〖心电图〗 ——〈开灯心语〉 生活就像 ——心电图: 一帆风顺, 证明 ——你没了; 起起伏伏, 说明你 —...

  • 心电图

    轻而易举 就偷走了我的心 我真怕 她一张嘴 就说出了我心中 不可告人的 天大的秘密

  • 心电图

    图图写写 打通神经 如果用心揣摩 每一句话背后都藏着汹涌奔腾的真理 它也许是黄河,也许是夸克 穿透躯体一阵呕吐 那...

  • 心电图

    他说 “我很想你” 他说 “因为我很在意你。” “我在乎的是你,不是其他那些七七八八的” 今晚于我来说很甜,比赵医...

  • 心电图

    今天一定要搞定,改变自己的形象先

网友评论

      本文标题:心电图动画

      本文链接:https://www.haomeiwen.com/subject/aauiixtx.html