心电图动画效果

简介:

心电图动画效果

 

效果

 

源码

https://github.com/YouXianMing/Animations


//
//  BezierPathViewController.m
//  Animations
//
//  Created by YouXianMing on 16/1/11.
//  Copyright © 2016年 YouXianMing. All rights reserved.
//

#import "BezierPathViewController.h"
#import "UIView+SetRect.h"
#import "CALayer+SetRect.h"
#import "UIFont+Fonts.h"
#import "UIView+AnimationProperty.h"
#import "GCD.h"

@interface BezierPathViewController ()

@property (nonatomic, strong) GCDTimer      *timer;
@property (nonatomic, strong) CAShapeLayer  *shapeLayer;

@end

@implementation BezierPathViewController

- (void)setup {
    
    [super setup];
    
    self.backgroundView.backgroundColor = [UIColor blackColor];
    
    // Used as background.
    {
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.frame         = CGRectMake(0, 0, 600, 300);
        shapeLayer.path          = [self path].CGPath;
        
        shapeLayer.fillColor   = [UIColor clearColor].CGColor;
        shapeLayer.strokeColor = [UIColor redColor].CGColor;
        shapeLayer.lineWidth   = 0.5f;
        shapeLayer.opacity     = 0.5f;
        shapeLayer.position    = self.contentView.middlePoint;
        shapeLayer.shadowColor = [UIColor redColor].CGColor;
        [shapeLayer setTransform:CATransform3DMakeScale(0.65, 0.65, 1.f)];
        
        [self.contentView.layer addSublayer:shapeLayer];
    }
    
    // Animation.
    {
        self.shapeLayer           = [CAShapeLayer layer];
        self.shapeLayer.frame     = CGRectMake(0, 0, 600, 300);
        self.shapeLayer.path      = [self path].CGPath;
        self.shapeLayer.strokeEnd = 0.f;
        
        self.shapeLayer.fillColor     = [UIColor clearColor].CGColor;
        self.shapeLayer.strokeColor   = [UIColor redColor].CGColor;
        self.shapeLayer.lineWidth     = 2.f;
        self.shapeLayer.position      = self.contentView.middlePoint;
        self.shapeLayer.shadowColor   = [UIColor redColor].CGColor;
        self.shapeLayer.shadowOpacity = 1.f;
        self.shapeLayer.shadowRadius  = 4.f;
        [self.shapeLayer setTransform:CATransform3DMakeScale(0.65, 0.65, 1.f)];
        [self.contentView.layer addSublayer:self.shapeLayer];
        
        CGFloat MAX = 0.98f;
        CGFloat GAP = 0.02;
        
        self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
        [self.timer event:^{
            
            CABasicAnimation *aniStart = [CABasicAnimation animationWithKeyPath:@"strokeStart"];
            aniStart.fromValue         = [NSNumber numberWithFloat:0.f];
            aniStart.toValue           = [NSNumber numberWithFloat:MAX];
            aniStart.duration          = 4.9f;
            
            CABasicAnimation *aniEnd   = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
            aniEnd.fromValue           = [NSNumber numberWithFloat:0.f + GAP];
            aniEnd.toValue             = [NSNumber numberWithFloat:MAX + GAP];
            aniEnd.duration            = 4.9f;
            
            CAAnimationGroup *group = [CAAnimationGroup animation];
            group.duration          = 4.9f;
            group.animations        = @[aniEnd, aniStart];
            
            self.shapeLayer.strokeStart   = MAX;
            self.shapeLayer.strokeEnd     = MAX + GAP;
            [self.shapeLayer addAnimation:group forKey:nil];
            
        } timeIntervalWithSecs:5.f delaySecs:1.f];
        [self.timer start];
    }
}

- (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)];
    bezierPath.lineCapStyle = kCGLineCapSquare;
    
    bezierPath.lineJoinStyle = kCGLineJoinBevel;
    
    [UIColor.blackColor setStroke];
    bezierPath.lineWidth = 1;
    [bezierPath stroke];
    
    return bezierPath;
}

- (void)buildTitleView {
    
    [super buildTitleView];
    
    [self.titleView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        [obj removeFromSuperview];
    }];
    
    // Title label.
    UILabel *headlinelabel      = [UILabel new];
    headlinelabel.font          = [UIFont AvenirWithFontSize:20.f];
    headlinelabel.textAlignment = NSTextAlignmentCenter;
    headlinelabel.textColor     = [[UIColor whiteColor] colorWithAlphaComponent:0.75f];
    headlinelabel.text          = self.title;
    [headlinelabel sizeToFit];
    
    headlinelabel.center = self.titleView.middlePoint;
    
    // Line.
    UIView *line         = [[UIView alloc] initWithFrame:CGRectMake(0, 63.5, self.view.width, 0.5f)];
    line.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.25f];
    [self.titleView addSubview:line];
    [self.titleView addSubview:headlinelabel];
    
    // Back button.
    UIImage  *image      = [UIImage imageNamed:@"backIconVer2"];
    UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 64)];
    backButton.center    = CGPointMake(20, self.titleView.middleY);
    [backButton setImage:image forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popSelf) forControlEvents:UIControlEventTouchUpInside];
    [backButton.imageView setContentMode:UIViewContentModeCenter];
    [self.titleView addSubview:backButton];
}

- (void)popSelf {
    
    [self popViewControllerAnimated:YES];
}

@end

细节

 


目录
相关文章
|
1月前
|
前端开发 程序员
给圆点添加呼吸动画,老板说我很有想法
【10月更文挑战第13天】给圆点添加呼吸动画,老板说我很有想法
给圆点添加呼吸动画,老板说我很有想法
|
1月前
Threejs用下个点方法实现模型沿着轨道行驶
这篇文章讲解了如何在Three.js中通过计算下一个路径点来控制模型沿轨迹行驶的方向,使用`lookAt`方法使模型面向行驶方向,实现了更加自然的移动效果。
45 1
|
3月前
|
开发框架
threejs做特效:实现物体的发光效果-EffectComposer详解!
【8月更文挑战第7天】实现物体的发光效果-EffectComposer详解!
353 6
threejs做特效:实现物体的发光效果-EffectComposer详解!
|
3月前
|
存储 算法 开发者
黑神话:悟空中的动态光照与阴影效果
【8月更文第26天】在《黑神话:悟空》这款游戏中,高质量的光照和阴影效果对于营造出逼真的游戏环境至关重要。为了达到这种效果,游戏开发团队采用了先进的实时渲染技术,包括动态光照和阴影技术。本文将详细介绍这些技术如何被用来增强场景的真实感。
133 3
|
3月前
|
前端开发
CSS动画新境界:打造逼真的水罐摇晃动效!
CSS动画新境界:打造逼真的水罐摇晃动效!
|
5月前
|
算法 图形学
【实现100个unity特效之3】使用PerlinNoise(柏林噪声)实现平滑的灯光闪烁效果
【实现100个unity特效之3】使用PerlinNoise(柏林噪声)实现平滑的灯光闪烁效果
99 0
|
5月前
|
图形学
【unity小技巧】实现没有动画的FPS武器摇摆和摆动效果
【unity小技巧】实现没有动画的FPS武器摇摆和摆动效果
34 0
|
6月前
如何用SCSS制作小铃铛振动/震动/摇晃/晃动的特效/效果?
如何用SCSS制作小铃铛振动/震动/摇晃/晃动的特效/效果?
|
11月前
|
前端开发
HTML+CSS制作七夕跳动的红心动画效果
HTML+CSS制作七夕跳动的红心动画效果
An动画基础之元件的影片剪辑动画与传统补间
An动画基础之元件的影片剪辑动画与传统补间
345 0
An动画基础之元件的影片剪辑动画与传统补间