Commit f555a88d cgx

优化均衡呼吸法、478呼吸法

1 个父辈 6aa13382
...@@ -1535,10 +1535,10 @@ ...@@ -1535,10 +1535,10 @@
children = ( children = (
D0F808F42803D4E70097899F /* Track.h */, D0F808F42803D4E70097899F /* Track.h */,
D0F808F32803D4E70097899F /* Track.m */, D0F808F32803D4E70097899F /* Track.m */,
D0C09EDE28007E5F00709D4C /* BreatheController.h */,
D0C09EDF28007E5F00709D4C /* BreatheController.m */,
D091BBB52808F9DA00487A50 /* BreathTextView.h */, D091BBB52808F9DA00487A50 /* BreathTextView.h */,
D091BBB62808F9DA00487A50 /* BreathTextView.m */, D091BBB62808F9DA00487A50 /* BreathTextView.m */,
D0C09EDE28007E5F00709D4C /* BreatheController.h */,
D0C09EDF28007E5F00709D4C /* BreatheController.m */,
); );
path = BreathingMethod; path = BreathingMethod;
sourceTree = "<group>"; sourceTree = "<group>";
......
...@@ -42,7 +42,6 @@ FOUNDATION_EXTERN NSString * const RelaxTrain; ...@@ -42,7 +42,6 @@ FOUNDATION_EXTERN NSString * const RelaxTrain;
+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes; + (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes;
+ (void)event:(NSString *)eventId label:(NSString *)label;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -27,17 +27,9 @@ NSString * const RelaxTrain = @"RelaxTrain"; ...@@ -27,17 +27,9 @@ NSString * const RelaxTrain = @"RelaxTrain";
+ (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes { + (void)event:(NSString *)eventId attributes:(NSDictionary *)attributes {
// 只统计正式环境的数据 // 只统计正式环境的数据
#if OPEN_DATA_STATISTICS == 1 #if OPEN_DATA_STATISTICS == 1
NSLog(@"eventId:%@, attributes:%@", eventId, attributes); // NSLog(@"eventId:%@, attributes:%@", eventId, attributes);
[MobClick event:eventId attributes:attributes]; [MobClick event:eventId attributes:attributes];
#endif #endif
} }
+ (void)event:(NSString *)eventId label:(NSString *)label {
// 只统计正式环境的数据
#if OPEN_DATA_STATISTICS == 1
NSLog(@"eventId:%@, label:%@", eventId, label);
[MobClick event:eventId label:label];
#endif
}
@end @end
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
typedef NS_ENUM(NSInteger, LottieStyle) { typedef NS_ENUM(NSInteger, LottieStyle) {
// 均衡呼吸法 // 均衡呼吸法
LottieStyleBalance, LottieStyleBalance,
// 舒睡呼吸法 // 舒睡呼吸法4-7-8
LottieStyleComfortable LottieStyleComfortable
}; };
......
...@@ -23,14 +23,15 @@ ...@@ -23,14 +23,15 @@
// 分钟选择控件 // 分钟选择控件
@property (nonatomic, strong) UIPickerView *minutePickerView; @property (nonatomic, strong) UIPickerView *minutePickerView;
@property (nonatomic, strong) NSArray *minuteDatas; @property (nonatomic, strong) NSArray *minuteDatas;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, strong) UILabel *timeLb; @property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *minuteLb; @property (nonatomic, strong) UILabel *minuteLb;
@property (nonatomic, strong) UIButton *startRelaxBtn; @property (nonatomic, strong) UIButton *startRelaxBtn;
@property (nonatomic, strong) UIButton *volumeBtn; @property (nonatomic, strong) UIButton *volumeBtn;
@property (nonatomic, strong) DOUAudioStreamer *audioStreamer; @property (nonatomic, strong) DOUAudioStreamer *audioStreamer;
@property (nonatomic, strong) NSTimer *controlTimer; @property (nonatomic, strong) NSTimer *controlTimer;
@property (nonatomic, assign) NSInteger minuteTime;
@property (nonatomic, assign) NSInteger playDuration; @property (nonatomic, assign) NSInteger playDuration;
@property (nonatomic, assign) NSInteger currentTime;
@end @end
@implementation BreatheController @implementation BreatheController
...@@ -40,8 +41,10 @@ ...@@ -40,8 +41,10 @@
self.view.backgroundColor = DarkColor; self.view.backgroundColor = DarkColor;
self.minuteTime = 1; // 默认2分钟
self.minuteDatas = @[@"1",@"2",@"3",@"4",@"5"]; self.currentIndex = 1;
self.currentTime = 0;
self.minuteDatas = @[@"1", @"2", @"3", @"4", @"5"];
self.rotateLottieFile = self.style == LottieStyleBalance ? @"relax_normal_lottie.json" : @"478normal_lottie.json"; self.rotateLottieFile = self.style == LottieStyleBalance ? @"relax_normal_lottie.json" : @"478normal_lottie.json";
self.zoomLottieFile = self.style == LottieStyleBalance ? @"relax_lottie.json" : @"478_lottie.json"; self.zoomLottieFile = self.style == LottieStyleBalance ? @"relax_lottie.json" : @"478_lottie.json";
...@@ -78,6 +81,14 @@ ...@@ -78,6 +81,14 @@
self.controlTimer = nil; self.controlTimer = nil;
if (self.audioStreamer) { if (self.audioStreamer) {
switch (self.audioStreamer.status) {
case DOUAudioStreamerPlaying: {
[self.audioStreamer pause];
}
break;
default:
break;
}
[self.audioStreamer stop]; [self.audioStreamer stop];
[self.audioStreamer removeObserver:self forKeyPath:@"status" context:kStatusKVOKey1]; [self.audioStreamer removeObserver:self forKeyPath:@"status" context:kStatusKVOKey1];
self.audioStreamer = nil; self.audioStreamer = nil;
...@@ -89,6 +100,7 @@ ...@@ -89,6 +100,7 @@
[self.view addSubview:self.rotateView]; [self.view addSubview:self.rotateView];
[self.view addSubview:self.zoomView]; [self.view addSubview:self.zoomView];
[self.view addSubview:self.minutePickerView]; [self.view addSubview:self.minutePickerView];
[self.minutePickerView selectRow:self.currentIndex inComponent:0 animated:YES];
self.timeLb = [UILabel new]; self.timeLb = [UILabel new];
self.timeLb.text = @"放松时长"; self.timeLb.text = @"放松时长";
...@@ -167,29 +179,67 @@ ...@@ -167,29 +179,67 @@
[self.zoomView play]; [self.zoomView play];
self.zoomView.hidden = NO; self.zoomView.hidden = NO;
self.playDuration = self.minuteTime * 60; NSTimeInterval interval = self.style == LottieStyleBalance ? 1.0 : 0.06;
self.controlTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES]; self.playDuration = [[self.minuteDatas objectAtIndex:self.currentIndex] integerValue] * 60;
self.controlTimer = [NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
[self.controlTimer fire];
[self.audioStreamer play]; [self.audioStreamer play];
} }
- (void)timerAction:(NSTimer *)timer { - (void)timerAction:(NSTimer *)timer {
self.playDuration--; if (self.style == LottieStyleBalance) {
if (self.playDuration % 4 == 0 && self.playDuration >= 0) { /*
AudioServicesPlaySystemSound(1520); 第0s、第5s震动,10s为一个周期,以s为单位
} */
if (self.playDuration == 0) { // 周期数
self.zoomView.animationProgress = 0; NSInteger cycle = self.currentTime / 10;
self.zoomView.hidden = YES; // 周期总时间
self.rotateView.hidden = NO; NSInteger cycleTotalTime = 10 * cycle;
self.timeLb.hidden = NO; if (self.currentTime == cycleTotalTime || self.currentTime == (5 + cycleTotalTime)) {
self.minuteLb.hidden = NO; AudioServicesPlaySystemSound(1520);
self.startRelaxBtn.hidden = NO; DSLog(@"当前时间:%lds, 第%ld个周期->第1个震动时间点:%lds, 第2个震动时间点:%lds", self.currentTime, cycle+1, cycleTotalTime, 5+cycleTotalTime);
self.minutePickerView.hidden = NO; }
self.currentTime++;
if (self.currentTime == self.playDuration) { [self stopBreathe]; }
} else if (self.style == LottieStyleComfortable) {
/*
第0s、第3.06s、第8.16s这3个点需要震动,15s一个周期
第0ms、第3060ms、第8160ms,以ms为单位
求3者最大公约数:
3060 8160 1500
306 816 150 10
102 272 50 30
51 136 25 60
最大公约数:60ms,每间隔60ms执行
*/
[self cancelAudioStreamer]; // 周期数
NSInteger cycle = self.currentTime / 15000;
// 周期总时间
NSInteger cycleTotalTime = 15000 * cycle;
if (self.currentTime == cycleTotalTime || self.currentTime == (51*60 + cycleTotalTime) || self.currentTime == (136*60 + cycleTotalTime)) {
AudioServicesPlaySystemSound(1520);
DSLog(@"当前时间:%ldms, 第%ld个周期->第1个震动时间点:%ldms, 第2个震动时间点:%ldms, 第3个震动时间点:%ldms", self.currentTime, cycle+1, cycleTotalTime, 51*60 + cycleTotalTime, 136*60 + cycleTotalTime);
}
self.currentTime+=60;
if (self.currentTime >= self.playDuration * 1000) { [self stopBreathe]; }
} }
} }
- (void)stopBreathe {
self.zoomView.animationProgress = 0;
self.zoomView.hidden = YES;
self.rotateView.hidden = NO;
self.timeLb.hidden = NO;
self.minuteLb.hidden = NO;
self.startRelaxBtn.hidden = NO;
self.minutePickerView.hidden = NO;
[self cancelAudioStreamer];
}
- (void)volumeControlAction:(UIButton *)sender { - (void)volumeControlAction:(UIButton *)sender {
sender.selected = !sender.selected; sender.selected = !sender.selected;
self.audioStreamer.volume = sender.selected ? 0 : 1; self.audioStreamer.volume = sender.selected ? 0 : 1;
...@@ -241,7 +291,7 @@ ...@@ -241,7 +291,7 @@
} }
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.minuteTime = [[self.minuteDatas objectAtIndex:row] integerValue]; self.currentIndex = row;
} }
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!