This commit is contained in:
2026-02-02 19:07:00 +08:00
parent 0416a64235
commit 993ec623af
3 changed files with 85 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
#import "KBVoiceInputBar.h"
#import "KBAiRecordButton.h"
#import "KBAiWaveformView.h"
#import <Masonry/Masonry.h>
@interface KBVoiceInputBar () <KBAiRecordButtonDelegate>
@@ -34,6 +35,8 @@
///
@property (nonatomic, strong) UIView *recordingView;
@property (nonatomic, strong) UIImageView *recordingCenterIconView;
@property (nonatomic, strong) KBAiWaveformView *leftWaveformView;
@property (nonatomic, strong) KBAiWaveformView *rightWaveformView;
///
@property (nonatomic, strong) UIView *cancelView;
@@ -146,6 +149,21 @@
make.width.height.mas_equalTo(36);
}];
[self.recordingView addSubview:self.leftWaveformView];
[self.recordingView addSubview:self.rightWaveformView];
[self.leftWaveformView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.recordingCenterIconView);
make.right.equalTo(self.recordingCenterIconView.mas_left).offset(-16);
make.width.mas_equalTo(84);
make.height.mas_equalTo(34);
}];
[self.rightWaveformView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.recordingCenterIconView);
make.left.equalTo(self.recordingCenterIconView.mas_right).offset(16);
make.width.mas_equalTo(84);
make.height.mas_equalTo(34);
}];
//
[self.inputContainer addSubview:self.cancelView];
[self.cancelView mas_makeConstraints:^(MASConstraintMaker *make) {
@@ -224,6 +242,11 @@
if (!self.toggleIconButton.hidden) {
[self.inputContainer bringSubviewToFront:self.toggleIconButton];
}
if (inputState == KBVoiceInputBarStateRecording) {
[self startRecordingWaveAnimationIfNeeded];
} else {
[self stopRecordingWaveAnimation];
}
[self updateCenterTextIfNeeded];
}
@@ -231,6 +254,11 @@
- (void)updateVolumeRMS:(float)rms {
[self.recordButton updateVolumeRMS:rms];
if (self.inputState == KBVoiceInputBarStateRecording) {
CGFloat safeRMS = MAX(rms, 0.6f);
[self.leftWaveformView updateWithRMS:safeRMS];
[self.rightWaveformView updateWithRMS:safeRMS];
}
}
#pragma mark - KBAiRecordButtonDelegate
@@ -370,6 +398,30 @@
return _recordingCenterIconView;
}
- (KBAiWaveformView *)leftWaveformView {
if (!_leftWaveformView) {
_leftWaveformView = [[KBAiWaveformView alloc] init];
_leftWaveformView.waveColor = [UIColor whiteColor];
_leftWaveformView.barCount = 7;
_leftWaveformView.barWidth = 3;
_leftWaveformView.barSpacing = 6;
_leftWaveformView.barHeightPattern = @[@0.35, @0.85, @0.5, @0.35, @0.9, @0.55, @0.35];
}
return _leftWaveformView;
}
- (KBAiWaveformView *)rightWaveformView {
if (!_rightWaveformView) {
_rightWaveformView = [[KBAiWaveformView alloc] init];
_rightWaveformView.waveColor = [UIColor whiteColor];
_rightWaveformView.barCount = 7;
_rightWaveformView.barWidth = 3;
_rightWaveformView.barSpacing = 6;
_rightWaveformView.barHeightPattern = @[@0.35, @0.85, @0.5, @0.35, @0.9, @0.55, @0.35];
}
return _rightWaveformView;
}
- (UIView *)cancelView {
if (!_cancelView) {
_cancelView = [[UIView alloc] init];
@@ -478,4 +530,20 @@
}
}
#pragma mark - Recording Wave
- (void)startRecordingWaveAnimationIfNeeded {
[self.leftWaveformView startIdleAnimation];
[self.rightWaveformView startIdleAnimation];
[self.leftWaveformView updateWithRMS:0.7f];
[self.rightWaveformView updateWithRMS:0.7f];
}
- (void)stopRecordingWaveAnimation {
[self.leftWaveformView stopAnimation];
[self.rightWaveformView stopAnimation];
[self.leftWaveformView reset];
[self.rightWaveformView reset];
}
@end