88
99#import " AudioRecordView.h"
1010#import " AudioManager.h"
11+ #import < QuartzCore/QuartzCore.h>
1112
1213@interface AudioRecordView () <AudioManagerDelegate>
1314
1415@property (nonatomic , strong ) UIImageView *imageView;
1516@property (nonatomic , assign ) AudioRecordViewTouchState touchState;
1617
18+ @property (nonatomic , strong ) UIView *recordBgView;
19+ @property (nonatomic , strong ) UIView *spreadView;
20+ @property (nonatomic , strong ) UIView *flashView;
21+
1722@end
1823
1924@implementation AudioRecordView
2025
21- - (instancetype )init {
22- self = [super init ];
23- if (self) {
24- [self initAudioRecordView ];
25- }
26- return self;
27- }
28-
29- - (instancetype )initWithCoder : (NSCoder *)coder {
30- self = [super initWithCoder: coder];
31- if (self) {
32- [self initAudioRecordView ];
33- }
34- return self;
35- }
36-
3726- (instancetype )initWithFrame : (CGRect)frame {
3827 self = [super initWithFrame: frame];
3928 if (self) {
40- [self initAudioRecordView ];
29+ _isRecording = NO ;
30+
31+ _recordBgView = [[UIView alloc ] initWithFrame: CGRectMake (-15 , -15 , self .frame.size.width+30 , self .frame.size.height+30 )];
32+ _recordBgView.backgroundColor = [UIColor colorWithRed: 0 .8f green: 0 .8f blue: 0 .8f alpha: 0 .1f ];
33+ _recordBgView.layer .cornerRadius = _recordBgView.frame .size .width /2 ;
34+ _recordBgView.layer .borderColor = [[UIColor colorWithRGBHex: 0xdddddd ] CGColor ];
35+ _recordBgView.layer .borderWidth = 1 ;
36+ _recordBgView.hidden = YES ;
37+ [self addSubview: _recordBgView];
38+
39+ _spreadView = [[UIView alloc ] initWithFrame: _recordBgView.frame];
40+ _spreadView.layer .cornerRadius = _recordBgView.frame .size .width /2 ;
41+ _spreadView.layer .borderColor = [[UIColor colorWithRGBHex: 0xdddddd ] CGColor ];
42+ _spreadView.layer .borderWidth = 1 ;
43+ _spreadView.alpha = 0 ;
44+ [self addSubview: _spreadView];
45+
46+ _imageView = [[UIImageView alloc ] initWithFrame: self .bounds];
47+ _imageView.backgroundColor = [UIColor colorWithRGBHex: 0x2faeea ];
48+ _imageView.layer .cornerRadius = self.frame .size .width /2 ;
49+ _imageView.contentMode = UIViewContentModeCenter;
50+ [self addSubview: _imageView];
51+
52+ _flashView = [[UIView alloc ] initWithFrame: self .bounds];
53+ _flashView.backgroundColor = [UIColor whiteColor ];
54+ _flashView.layer .cornerRadius = _flashView.frame .size .width /2 ;
55+ _flashView.alpha = 0 ;
56+ [self addSubview: _flashView];
57+
58+ [self addTarget: self action: @selector (onTouchDown: ) forControlEvents: UIControlEventTouchDown];
59+ [self addTarget: self action: @selector (onTouchUpInside: ) forControlEvents: UIControlEventTouchUpInside];
60+ [self addTarget: self action: @selector (onTouchUpOutside: ) forControlEvents: UIControlEventTouchUpOutside];
4161 }
4262 return self;
4363}
4464
45- - (void )initAudioRecordView {
46- self.backgroundColor = [UIColor colorWithRGBHex: 0x2faeea ];
47- self.layer .cornerRadius = self.frame .size .width /2 ;
48-
49- _isRecording = NO ;
50-
51- [self addTarget: self action: @selector (onTouchDown: ) forControlEvents: UIControlEventTouchDown];
52- [self addTarget: self action: @selector (onTouchUpInside: ) forControlEvents: UIControlEventTouchUpInside];
53- [self addTarget: self action: @selector (onTouchUpOutside: ) forControlEvents: UIControlEventTouchUpOutside];
65+ - (void )dealloc {
66+ [self stop ];
5467}
5568
5669- (void )record {
@@ -60,26 +73,29 @@ - (void)record {
6073 [AudioManager shared ].delegate = self;
6174 [[AudioManager shared ] recordWithValidator: _validator];
6275
76+ [self startAnimation ];
77+
6378 if (_delegate && [_delegate respondsToSelector: @selector (recordViewRecordStarted: )]) {
6479 [_delegate recordViewRecordStarted: self ];
6580 }
6681}
6782
6883- (void )stop {
6984 _isRecording = NO ;
70- [[AudioManager shared ] stopPlay ];
85+ [self stopAnimation ];
86+ [[AudioManager shared ] stopRecord ];
7187}
7288
7389- (void )onTouchDown : (id )sender {
7490 [self record ];
7591}
7692
7793- (void )onTouchUpInside : (id )sender {
78- [[AudioManager shared ] stopRecord ];
94+ [self stop ];
7995}
8096
8197- (void )onTouchUpOutside : (id )sender {
82- [[AudioManager shared ] stopRecord ];
98+ [self stop ];
8399}
84100
85101#pragma mark - touch
@@ -109,6 +125,36 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
109125 }
110126}
111127
128+ #pragma mark - Animation
129+
130+ - (void )startAnimation {
131+ _recordBgView.hidden = NO ;
132+ _spreadView.alpha = 1 .0f ;
133+ _spreadView.transform = CGAffineTransformMakeScale (1 .0f , 1 .0f );
134+ _flashView.alpha = 0 .6f ;
135+
136+ [UIView beginAnimations: @" RecordAnimation" context: nil ];
137+ [UIView setAnimationDelegate: self ];
138+ [UIView setAnimationDuration: 2 .0f ];
139+ [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
140+ [UIView setAnimationRepeatCount: FLT_MAX];
141+
142+ _flashView.alpha = 0 ;
143+ _spreadView.transform = CGAffineTransformMakeScale (1 .5f , 1 .5f );
144+ _spreadView.alpha = 0 ;
145+
146+ [UIView commitAnimations ];
147+ }
148+
149+ - (void )stopAnimation {
150+ [_flashView.layer removeAllAnimations ];
151+ [_spreadView.layer removeAllAnimations ];
152+
153+ _recordBgView.hidden = YES ;
154+ _spreadView.alpha = 0 ;
155+ _flashView.alpha = 0 ;
156+ }
157+
112158#pragma mark - AudioManagerDelegate
113159
114160- (void )didAudioRecordStarted : (AudioManager *)am {
@@ -122,7 +168,7 @@ - (void)didAudioRecording:(AudioManager *)am volume:(double)volume {
122168}
123169
124170- (void )didAudioRecordStoped : (AudioManager *)am file : (NSString *)file duration : (NSTimeInterval )duration successfully : (BOOL )successfully {
125- _isRecording = NO ;
171+ NSLog ( @" didAudioRecordStoped " ) ;
126172 if (_delegate && [_delegate respondsToSelector: @selector (recordViewRecordFinished:file:duration: )]) {
127173 [_delegate recordViewRecordFinished: self file: file duration: duration];
128174 }
0 commit comments