recordingView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // recordingView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2025/3/28.
  6. //
  7. #import "recordingView.h"
  8. #import "AudioRecorderManager.h"
  9. @interface recordingView ()
  10. @property(nonatomic,strong)UILabel * titlelabel;
  11. @property(nonatomic,strong)UILabel * timerlabel;
  12. @property(nonatomic,assign)NSInteger second;
  13. @property(nonatomic,strong)NSTimer * secondTimer;
  14. @end
  15. @implementation recordingView
  16. - (id)initWithFrame:(CGRect)frame{
  17. self = [super initWithFrame:frame];
  18. self.backgroundColor = [UIColor hwColor:@"000000" alpha:0.6];
  19. [self drawAnyView];
  20. return self;
  21. }
  22. -(void)drawAnyView{
  23. UIView *whiteBgView = [[UIView alloc] init];
  24. whiteBgView.backgroundColor = [UIColor whiteColor];
  25. [self addSubview:whiteBgView];
  26. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  27. make.left.mas_equalTo(0.f);
  28. make.height.mas_equalTo(238.f + AdaptTabHeight);
  29. make.right.mas_equalTo(0.f);
  30. make.bottom.mas_equalTo(0.f);
  31. }];
  32. /*上圆角*/
  33. UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W, 238.f + AdaptTabHeight)
  34. byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight
  35. cornerRadii:CGSizeMake(12, 12)];
  36. CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
  37. maskLayer.frame = CGRectMake(0, 0, SCREEN_W, 238.f + AdaptTabHeight);
  38. maskLayer.path = maskPath.CGPath;
  39. whiteBgView.layer.mask = maskLayer;
  40. UIButton *recordBut = [[UIButton alloc] init];
  41. [recordBut setBackgroundImage:[UIImage imageNamed:@"white_record_end_icon"] forState:UIControlStateNormal];
  42. [recordBut addTarget:self action:@selector(didClickButFun) forControlEvents:UIControlEventTouchUpInside];
  43. [whiteBgView addSubview:recordBut];
  44. [recordBut mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.width.mas_equalTo(78.f);
  46. make.height.mas_equalTo(78.f);
  47. make.centerX.mas_equalTo(0.f);
  48. make.bottom.mas_equalTo(-12.f - AdaptTabHeight);
  49. }];
  50. //
  51. UIImageView *recordingTipImageView = [[UIImageView alloc] init];
  52. recordingTipImageView.image = [UIImage imageNamed:@"recording_tip"];
  53. [whiteBgView addSubview:recordingTipImageView];
  54. [recordingTipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.width.mas_equalTo(323.f*AUTOSCALE);
  56. make.height.mas_equalTo(52.f*AUTOSCALE);
  57. make.centerX.mas_equalTo(0.f);
  58. make.bottom.equalTo(recordBut.mas_top).offset(-20);
  59. }];
  60. //标题
  61. _titlelabel = [[UILabel alloc] init];
  62. [whiteBgView addSubview:_titlelabel];
  63. _titlelabel.font = [UIFont systemFontOfSize:14.f];
  64. _titlelabel.textAlignment = NSTextAlignmentCenter;
  65. [_titlelabel setTextColor:HW0A132BColor];
  66. [_titlelabel mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.mas_equalTo(12.0);
  68. make.top.mas_equalTo(15.0);
  69. make.height.mas_equalTo(20.0);
  70. make.right.mas_equalTo(-12.f);
  71. }];
  72. _timerlabel = [[UILabel alloc] init];
  73. [whiteBgView addSubview:_timerlabel];
  74. _timerlabel.font = [UIFont systemFontOfSize:12.f];
  75. _timerlabel.text = @"00:00:00";
  76. _timerlabel.textAlignment = NSTextAlignmentCenter;
  77. [_timerlabel setTextColor:[UIColor hwColor:@"979797"]];
  78. [_timerlabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.left.mas_equalTo(12.0);
  80. make.top.mas_equalTo(15.0);
  81. make.height.mas_equalTo(20.0);
  82. make.right.mas_equalTo(-12.f);
  83. }];
  84. }
  85. #pragma mark 开始录音
  86. - (void)beginRecordFunWith:(NSInteger)curIndex;
  87. {
  88. NSString *curName = [[NSString alloc] initWithFormat:@"record%ld.m4a",curIndex];
  89. _titlelabel.text = curName;
  90. [AudioRecorderManager sharedManager].curRecordName = curName;
  91. [[AudioRecorderManager sharedManager] startRecording];
  92. //_secondTimer in
  93. _secondTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerChange) userInfo:nil repeats:YES];
  94. [[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
  95. }
  96. #pragma mark 一秒一次的timer检测
  97. - (void)timerChange{
  98. }
  99. - (void)didClickButFun
  100. {
  101. [[AudioRecorderManager sharedManager] stopRecording];
  102. if (_didClickRecordEndFun) {
  103. _didClickRecordEndFun();
  104. }
  105. }
  106. @end