美文网首页
音频、录制、动画、仿微信

音频、录制、动画、仿微信

作者: 熙棋 | 来源:发表于2022-11-21 15:04 被阅读0次

    废话不多说直接上代码,简单明了。

    #import "ViewController.h"

    @interface ViewController ()

    @property (nonatomic,weak) CAShapeLayer *layer;

    @property (nonatomic,weak) CAShapeLayer *layer2;

    @property (nonatomic,strong) NSMutableArray *dataArr;

    @property (nonatomic,strong) UIBezierPath *path;

    @property (nonatomic,strong) NSTimer *timer;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.dataArr = [NSMutableArray arrayWithArray:@[@0.01,@0.01,@0.01,@0.01,@0.01,@0.01,@0.01,@0.01]];

        [self startMeterTimer];

    }

    #pragma mark- displayLink

    - (void)startMeterTimer {

        [self stopTimer];

        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(timerRefresh) userInfo:nil repeats:YES];

    }

    - (void)stopTimer {

        [self.timer invalidate];

    }

    - (void)timerRefresh {

        CGFloatheight = (arc4random() %10+1)/10.0;

        [self.dataArr removeLastObject];

        [self.dataArr insertObject:@(height) atIndex:0];

        [self creatLayer];

        [self creatLayer2];

    }

    - (void)creatLayer {

        self.path= [UIBezierPathbezierPath];

        CGFloatheight =CGRectGetHeight(self.layer.frame);

        for(inti =0; i <self.dataArr.count; i++) {

            CGFloatx =100- (i *5+5);

            CGFloatH = [self.dataArr[i]floatValue] * height;

            CGFloatbeginY = height /2.0- H /2.0;

            CGFloatendY = height /2.0+ H /2.0;

            [_pathmoveToPoint:CGPointMake(x, beginY)];

            [_path addLineToPoint:CGPointMake(x, endY)];

        }

        self.layer.path=_path.CGPath;

    }

    - (CAShapeLayer *)layer {

        if(_layer==nil) {

            CAShapeLayer *layer = [CAShapeLayer layer];

            layer.frame=CGRectMake(100,200,100,20);

            layer.strokeColor= [UIColorredColor].CGColor;

            layer.lineWidth=3;

            [self.view.layeraddSublayer:layer];

            _layer= layer;

        }

        return_layer;

    }

    - (void)creatLayer2 {

        self.path= [UIBezierPathbezierPath];

        CGFloatheight =CGRectGetHeight(self.layer2.frame);

        for(inti =0; i <self.dataArr.count; i++) {

            CGFloatx = (i *5+5);

            CGFloatH = [self.dataArr[i]floatValue] * height;

            CGFloatbeginY = height /2.0- H /2.0;

            CGFloatendY = height /2.0+ H /2.0;

            [_pathmoveToPoint:CGPointMake(x, beginY)];

            [_path addLineToPoint:CGPointMake(x, endY)];

        }

        self.layer2.path=_path.CGPath;

    }

    - (CAShapeLayer *)layer2 {

        if(_layer2==nil) {

            CAShapeLayer *layer = [CAShapeLayer layer];

            layer.frame=CGRectMake(190,200,100,20);

            layer.strokeColor= [UIColorredColor].CGColor;

            layer.lineWidth=3;

            [self.view.layeraddSublayer:layer];

            _layer2= layer;

        }

        return _layer2;

    }

    @end

    相关文章

      网友评论

          本文标题:音频、录制、动画、仿微信

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