Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

增加模仿微信录音的HUD,并修改部分可能引起问题的代码。 #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ChatKit/ChatKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@
9AC44E9D1E15154300619112 /* UITableView+FDTemplateLayoutCellDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 9AC44D7D1E15154300619112 /* UITableView+FDTemplateLayoutCellDebug.m */; };
9AC44E9E1E15154300619112 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 9AC44D7E1E15154300619112 /* LICENSE */; };
9AC44E9F1E15154300619112 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = 9AC44D7F1E15154300619112 /* README.md */; };
FAE19C971EEA8EE4003B95FE /* LCCKRecordAudioHUD.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE19C951EEA8EE4003B95FE /* LCCKRecordAudioHUD.h */; };
FAE19C981EEA8EE4003B95FE /* LCCKRecordAudioHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = FAE19C961EEA8EE4003B95FE /* LCCKRecordAudioHUD.m */; };
FAE19C9E1EEA95CC003B95FE /* LCCKRecordAudioHUD.bundle in Resources */ = {isa = PBXBuildFile; fileRef = FAE19C9D1EEA95CC003B95FE /* LCCKRecordAudioHUD.bundle */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -1005,6 +1008,9 @@
9AC44D7E1E15154300619112 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
9AC44D7F1E15154300619112 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
A9601FCE9729A0FE4669D33E /* libPods-ChatKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ChatKit.a"; sourceTree = BUILT_PRODUCTS_DIR; };
FAE19C951EEA8EE4003B95FE /* LCCKRecordAudioHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCCKRecordAudioHUD.h; sourceTree = "<group>"; };
FAE19C961EEA8EE4003B95FE /* LCCKRecordAudioHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCCKRecordAudioHUD.m; sourceTree = "<group>"; };
FAE19C9D1EEA95CC003B95FE /* LCCKRecordAudioHUD.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = LCCKRecordAudioHUD.bundle; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1276,6 +1282,8 @@
9AAFA1871E14FBA3006618E0 /* LCCKInputViewPluginTakePhoto.m */,
9AAFA1881E14FBA3006618E0 /* LCCKProgressHUD.h */,
9AAFA1891E14FBA3006618E0 /* LCCKProgressHUD.m */,
FAE19C951EEA8EE4003B95FE /* LCCKRecordAudioHUD.h */,
FAE19C961EEA8EE4003B95FE /* LCCKRecordAudioHUD.m */,
);
path = ChatBar;
sourceTree = "<group>";
Expand Down Expand Up @@ -1354,6 +1362,7 @@
9AAFA1B21E14FBA4006618E0 /* Other.bundle */,
9AAFA1B31E14FBA4006618E0 /* Placeholder.bundle */,
9AAFA1B41E14FBA4006618E0 /* VoiceMessageSource.bundle */,
FAE19C9D1EEA95CC003B95FE /* LCCKRecordAudioHUD.bundle */,
);
path = Resources;
sourceTree = "<group>";
Expand Down Expand Up @@ -2137,6 +2146,7 @@
9AAFA21A1E14FBA4006618E0 /* NSMutableArray+LCCKMessageExtention.h in Headers */,
9AAFA2631E14FBA5006618E0 /* LCCKInputViewPluginTakePhoto.h in Headers */,
9AC44E6F1E15154300619112 /* POPSpringSolver.h in Headers */,
FAE19C971EEA8EE4003B95FE /* LCCKRecordAudioHUD.h in Headers */,
9AAFA24B1E14FBA4006618E0 /* LCCKFaceManager.h in Headers */,
9AAFA2D01E14FBA6006618E0 /* Mp3Recorder.h in Headers */,
9AAFA2B71E14FBA5006618E0 /* LCCKAlertController.h in Headers */,
Expand Down Expand Up @@ -2422,6 +2432,7 @@
9AAFA2871E14FBA5006618E0 /* MBProgressHUD.bundle in Resources */,
9AC44E181E15154300619112 /* [email protected] in Resources */,
9AAFA2821E14FBA5006618E0 /* ChatKeyboard.bundle in Resources */,
FAE19C9E1EEA95CC003B95FE /* LCCKRecordAudioHUD.bundle in Resources */,
9AC44E9E1E15154300619112 /* LICENSE in Resources */,
9AC44E0D1E15154300619112 /* [email protected] in Resources */,
9AC44E231E15154300619112 /* UIBarButtonItemArrowRight.png in Resources */,
Expand Down Expand Up @@ -2556,6 +2567,7 @@
9AC44DC51E15154300619112 /* ViewController+MASAdditions.m in Sources */,
9AAFA2D91E14FBA6006618E0 /* LCCKSwipeView.m in Sources */,
9AC44DCF1E15154300619112 /* MJRefreshBackFooter.m in Sources */,
FAE19C981EEA8EE4003B95FE /* LCCKRecordAudioHUD.m in Sources */,
9AC44E951E15154300619112 /* UIView+WebCacheOperation.m in Sources */,
9AC44E511E15154300619112 /* POPAnimationRuntime.mm in Sources */,
9AC44D9C1E15154300619112 /* FDTransformLayer.m in Sources */,
Expand Down
138 changes: 71 additions & 67 deletions ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#import "LCCKChatBar.h"
#import "LCCKChatMoreView.h"
#import "LCCKChatFaceView.h"
#import "LCCKProgressHUD.h"
#import "LCCKRecordAudioHUD.h"
#import "Mp3Recorder.h"
#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
#import "Masonry.h"
#endif
#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
#import "Masonry.h"
#endif
#import "LCCKUIService.h"
#import "UIImage+LCCKExtension.h"
#import "NSString+LCCKExtension.h"
Expand Down Expand Up @@ -333,25 +333,6 @@ - (void)textViewDidChange:(UITextView *)textView
});
}

#pragma mark - MP3RecordedDelegate

- (void)endConvertWithMP3FileName:(NSString *)fileName {
if (fileName) {
[LCCKProgressHUD dismissWithProgressState:LCCKProgressSuccess];
[self sendVoiceMessage:fileName seconds:[LCCKProgressHUD seconds]];
} else {
[LCCKProgressHUD dismissWithProgressState:LCCKProgressError];
}
}

- (void)failRecord {
[LCCKProgressHUD dismissWithProgressState:LCCKProgressError];
}

- (void)beginConvert {
[LCCKProgressHUD changeSubTitle:@"正在转换..."];
}

#pragma mark - LCCKChatFaceViewDelegate

- (void)faceViewSendFace:(NSString *)faceName {
Expand Down Expand Up @@ -422,7 +403,66 @@ - (void)beginInputing {
[self.textView becomeFirstResponder];
}

#pragma mark - MP3RecordedDelegate
- (void)averagePowerWithVolume:(CGFloat)volume {
[LCCKRecordAudioHUD changeVolume:volume];
}

- (void)endConvertWithMP3FileName:(NSString *)fileName {
if (fileName) {
[LCCKRecordAudioHUD dismissWithState:LCCKRecoderResultStateSuccess];
[self sendVoiceMessage:fileName seconds:[LCCKRecordAudioHUD seconds]];
} else {
[LCCKRecordAudioHUD dismissWithState:LCCKRecoderResultStateFail];
}
}

- (void)tooShortFailRecord {
[LCCKRecordAudioHUD dismissWithState:LCCKRecoderResultStateShort];
}

#pragma mark - Private Methods
/**
* 开始录音
*/
- (void)startRecordVoice {
[LCCKRecordAudioHUD show];
self.voiceRecordButton.selected = YES;
[self.MP3 startRecord];
}

/**
* 取消录音
*/
- (void)cancelRecordVoice {
[LCCKRecordAudioHUD dismissWithState:LCCKRecoderResultStateCancel];
self.voiceRecordButton.selected = NO;
[self.MP3 cancelRecord];
}

/**
* 录音结束
*/
- (void)confirmRecordVoice {
self.voiceRecordButton.selected = NO;
[self.MP3 stopRecord];
}

/**
* 更新录音显示状态,手指向上滑动后提示松开取消录音
*/
- (void)updateCancelRecordVoice {
[LCCKRecordAudioHUD changeProgressState:LCCKRecordProgressStateOutSide];
[_voiceRecordButton setTitle:@"松开 取消" forState:UIControlStateSelected];
}

/**
* 更新录音状态,手指重新滑动到范围内,提示向上取消录音
*/
- (void)updateContinueRecordVoice {
[LCCKRecordAudioHUD changeProgressState:LCCKRecordProgressStateInSide];
[_voiceRecordButton setTitle:@"松开 结束" forState:UIControlStateSelected];
}

- (void)keyboardWillHide:(NSNotification *)notification {
NSString *reason = [NSString stringWithFormat:@"🔴类名与方法名:%@(在第%@行),描述:%@", @(__PRETTY_FUNCTION__), @(__LINE__), @"Should update on main thread"];
Expand Down Expand Up @@ -496,47 +536,11 @@ - (void)setup {
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(confirmRecordVoice) name:kLCCKRecordAudioTooLong object:nil];
self.backgroundColor = self.messageInputViewBackgroundColor;
[self setupConstraints];
}

/**
* 开始录音
*/
- (void)startRecordVoice {
[LCCKProgressHUD show];
self.voiceRecordButton.highlighted = YES;
[self.MP3 startRecord];
}

/**
* 取消录音
*/
- (void)cancelRecordVoice {
[LCCKProgressHUD dismissWithMessage:@"取消录音"];
self.voiceRecordButton.highlighted = NO;
[self.MP3 cancelRecord];
}

/**
* 录音结束
*/
- (void)confirmRecordVoice {
[self.MP3 stopRecord];
}

/**
* 更新录音显示状态,手指向上滑动后提示松开取消录音
*/
- (void)updateCancelRecordVoice {
[LCCKProgressHUD changeSubTitle:@"松开取消录音"];
}

/**
* 更新录音状态,手指重新滑动到范围内,提示向上取消录音
*/
- (void)updateContinueRecordVoice {
[LCCKProgressHUD changeSubTitle:@"向上滑动取消录音"];

[LCCKRecordAudioHUD instance];
}

- (void)setShowType:(LCCKFunctionViewShowType)showType {
Expand Down Expand Up @@ -650,7 +654,7 @@ - (void)showMoreView:(BOOL)show {

- (void)showVoiceView:(BOOL)show {
self.voiceButton.selected = show;
self.voiceRecordButton.selected = show;
// self.voiceRecordButton.selected = show;
self.voiceRecordButton.hidden = !show;
self.textView.hidden = !self.voiceRecordButton.hidden;
}
Expand Down Expand Up @@ -773,10 +777,10 @@ - (UIButton *)voiceRecordButton {
UIImage *voiceRecordButtonNormalBackgroundImage = [[self imageInBundlePathForImageName:@"VoiceBtn_Black"] resizableImageWithCapInsets:edgeInsets resizingMode:UIImageResizingModeStretch];
UIImage *voiceRecordButtonHighlightedBackgroundImage = [[self imageInBundlePathForImageName:@"VoiceBtn_BlackHL"] resizableImageWithCapInsets:edgeInsets resizingMode:UIImageResizingModeStretch];
[_voiceRecordButton setBackgroundImage:voiceRecordButtonNormalBackgroundImage forState:UIControlStateNormal];
[_voiceRecordButton setBackgroundImage:voiceRecordButtonHighlightedBackgroundImage forState:UIControlStateHighlighted];
[_voiceRecordButton setBackgroundImage:voiceRecordButtonHighlightedBackgroundImage forState:UIControlStateSelected];
_voiceRecordButton.titleLabel.font = [UIFont systemFontOfSize:14.0f];
[_voiceRecordButton setTitle:@"按住 说话" forState:UIControlStateNormal];
[_voiceRecordButton setTitle:@"松开 结束" forState:UIControlStateHighlighted];
[_voiceRecordButton setTitle:@"松开 结束" forState:UIControlStateSelected];
[_voiceRecordButton addTarget:self action:@selector(startRecordVoice) forControlEvents:UIControlEventTouchDown];
[_voiceRecordButton addTarget:self action:@selector(cancelRecordVoice) forControlEvents:UIControlEventTouchUpOutside];
[_voiceRecordButton addTarget:self action:@selector(confirmRecordVoice) forControlEvents:UIControlEventTouchUpInside];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// LCCKRecordAudioHUD.h
// LCCKChatBarExample
//
// Created by alex-W on 2017/6/7.
// Copyright © 2017年 http://codewpf.com/ . All rights reserved.
//

#import <UIKit/UIKit.h>

#define kLCCKRecordAudioTooLong @"kLCCKRecordAudioTooLong"

/**
音频记录结果

- LCCKRecoderResultStateSuccess: 成功
- LCCKRecoderResultStateFail: 失败 转换音频格式错误
- LCCKRecoderResultStateShort: 失败 音频时长太短不发送
- LCCKRecoderResultStateLong: 成功 音频时长太长结束并发送
- LCCKRecoderResultStateCancel: 取消
*/
typedef NS_ENUM(NSUInteger, LCCKRecordResultState) {
LCCKRecoderResultStateSuccess ,
LCCKRecoderResultStateFail ,
LCCKRecoderResultStateShort ,
LCCKRecoderResultStateLong ,
LCCKRecoderResultStateCancel ,
};


/**
音频记录状态

- LCCKRecordProgressStateOutSide: 手指松开,取消发送
- LCCKRecordProgressStateInSide: 手指上滑,取消发送
*/
typedef NS_ENUM(NSUInteger, LCCKRecordProgressState) {
LCCKRecordProgressStateOutSide,
LCCKRecordProgressStateInSide,
};

@interface LCCKRecordAudioHUD : UIView
/** 是否正在显示 */
@property (nonatomic, assign, readonly, getter=isShowing) BOOL showing;
/**
HUD 单例

@return 单例
*/
+ (LCCKRecordAudioHUD *)instance;

/**
显示录音指示器
*/
+ (void)show;

/**
隐藏录音指示器,根据结果

@param recderState 结果
*/
+ (void)dismissWithState:(LCCKRecordResultState)resultState;


/**
修改录音指示器,根据状态

@param progressState 状态
*/
+ (void)changeProgressState:(LCCKRecordProgressState)progressState;


/**
修改音量

@param level 音量
*/
+ (void)changeVolume:(NSInteger)level;


/**
录音总时间

@return 录音总时间
*/
+ (NSInteger)seconds;

@end



Loading