123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //
- // recordingView.m
- // 双子星云手机
- //
- // Created by xd h on 2025/3/28.
- //
- #import "recordingView.h"
- #import "AudioRecorderManager.h"
- @interface recordingView ()
- @property(nonatomic,strong)UILabel * titlelabel;
- @property(nonatomic,strong)UILabel * timerlabel;
- @property(nonatomic,assign)NSInteger second;
- @property(nonatomic,strong)NSTimer * secondTimer;
- @property(nonatomic,strong)UIImageView *recordingTipImageView;
- @end
- @implementation recordingView
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
-
- _second = 0;
- self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
- [self drawAnyView];
-
- return self;
- }
- -(void)drawAnyView{
-
- UIView *whiteBgView = [[UIView alloc] init];
- whiteBgView.backgroundColor = [UIColor whiteColor];
- [self addSubview:whiteBgView];
-
- [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0.f);
- make.height.mas_equalTo(238.f + AdaptTabHeight);
- make.right.mas_equalTo(0.f);
- make.bottom.mas_equalTo(0.f);
- }];
-
- /*上圆角*/
- UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W, 238.f + AdaptTabHeight)
- byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight
- cornerRadii:CGSizeMake(12, 12)];
- CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
- maskLayer.frame = CGRectMake(0, 0, SCREEN_W, 238.f + AdaptTabHeight);
- maskLayer.path = maskPath.CGPath;
- whiteBgView.layer.mask = maskLayer;
- UIButton *recordBut = [[UIButton alloc] init];
- [recordBut setBackgroundImage:[UIImage imageNamed:@"white_record_end_icon"] forState:UIControlStateNormal];
- [recordBut addTarget:self action:@selector(didClickButFun) forControlEvents:UIControlEventTouchUpInside];
- [whiteBgView addSubview:recordBut];
-
- [recordBut mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(78.f);
- make.height.mas_equalTo(78.f);
- make.centerX.mas_equalTo(0.f);
- make.bottom.mas_equalTo(-12.f - AdaptTabHeight);
- }];
-
- //
- _recordingTipImageView = [[UIImageView alloc] init];
- _recordingTipImageView.image = [UIImage imageNamed:@"recording_tip"];
- [whiteBgView addSubview:_recordingTipImageView];
-
- [_recordingTipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(323.f*AUTOSCALE);
- make.height.mas_equalTo(52.f*AUTOSCALE);
- make.centerX.mas_equalTo(0.f);
- make.bottom.equalTo(recordBut.mas_top).offset(-20);
- }];
-
-
- //标题
- _titlelabel = [[UILabel alloc] init];
- [whiteBgView addSubview:_titlelabel];
- _titlelabel.font = [UIFont systemFontOfSize:14.f];
- _titlelabel.textAlignment = NSTextAlignmentCenter;
- [_titlelabel setTextColor:HW0A132BColor];
- [_titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(12.0);
- make.top.mas_equalTo(15.0);
- make.height.mas_equalTo(20.0);
- make.right.mas_equalTo(-12.f);
- }];
-
- _timerlabel = [[UILabel alloc] init];
- [whiteBgView addSubview:_timerlabel];
- _timerlabel.font = [UIFont systemFontOfSize:12.f];
- _timerlabel.text = @"00:00:00";
- _timerlabel.textAlignment = NSTextAlignmentCenter;
- [_timerlabel setTextColor:[UIColor hwColor:@"979797"]];
- [_timerlabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(12.0);
- make.top.equalTo(_titlelabel.mas_bottom).offset(10);
- make.height.mas_equalTo(20.0);
- make.right.mas_equalTo(-12.f);
- }];
-
- }
- #pragma mark 开始录音
- - (void)beginRecordFunWith:(NSInteger)curIndex;
- {
- NSString *curName = [[NSString alloc] initWithFormat:@"record%ld.m4a",curIndex];
- _titlelabel.text = curName;
- [AudioRecorderManager sharedManager].curRecordName = curName;
- [[AudioRecorderManager sharedManager] startRecording];
-
- //_secondTimer in
- _secondTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
-
- [self startBreathingAnimationWithImageView:_recordingTipImageView];
- }
- #pragma mark 一秒一次的timer检测
- - (void)timerChange{
- _second +=1;
-
- KWeakSelf
- mainBlock(^{
- [weakSelf setTimeStringFun];
- });
-
- }
- #pragma mark 设置时间
- - (void)setTimeStringFun
- {
- // 时长 totalTime
- NSInteger hour = 0;
- NSInteger min = 0;
- NSInteger second = 0;
-
- hour = _second / 60 /60;
- min = (_second -60*hour)/60;
- second = _second -60*hour - 60 *min;
-
- NSString* totalTimeStr = [[NSString alloc] initWithFormat:@"%02ld:%02ld:%02ld",hour,min,second];
- _timerlabel.text = totalTimeStr;
- }
- - (void)didClickButFun
- {
- [self stopBreathingAnimationWithImageView:_recordingTipImageView];
- [_secondTimer invalidate];
- _secondTimer = nil;
-
- [[AudioRecorderManager sharedManager] stopRecording];
- if (_didClickRecordEndFun) {
- _didClickRecordEndFun();
- }
- }
- - (void)startBreathingAnimationWithImageView:(UIImageView *)imageView {
- CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
- animation.duration = 2.0;
- animation.values = @[@1.0, @1.01, @1.02, @0.98, @1.0]; // 缩放值序列
- animation.keyTimes = @[@0, @0.25, @0.5, @0.75, @1]; // 关键帧时间点
- animation.repeatCount = HUGE_VALF;
-
- [imageView.layer addAnimation:animation forKey:@"keyframeScale"];
- }
- - (void)stopBreathingAnimationWithImageView:(UIImageView *)imageView
- {
- [imageView.layer removeAllAnimations];
- }
- @end
|