Commit f37dedf2 cgx

基本完成放松训练页面

1 个父辈 e208d964
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
39CC172FB610DA5F29120B56 /* Pods_DreamSleep.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D11699D88A7A7BDB6168B71 /* Pods_DreamSleep.framework */; settings = {ATTRIBUTES = (Required, ); }; }; 39CC172FB610DA5F29120B56 /* Pods_DreamSleep.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D11699D88A7A7BDB6168B71 /* Pods_DreamSleep.framework */; settings = {ATTRIBUTES = (Required, ); }; };
D00291892816CD4500C0573B /* DsCacheUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D00291882816CD4500C0573B /* DsCacheUtils.m */; }; D00291892816CD4500C0573B /* DsCacheUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = D00291882816CD4500C0573B /* DsCacheUtils.m */; };
D0031549284DAC0D00CFE94D /* RelaxBodyView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0031548284DAC0D00CFE94D /* RelaxBodyView.m */; };
D003154C284DF46F00CFE94D /* RelaxTrainCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D003154B284DF46F00CFE94D /* RelaxTrainCell.m */; };
D00A63572824C42300AFFEAA /* DSNetworkCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D00A63562824C42300AFFEAA /* DSNetworkCache.m */; }; D00A63572824C42300AFFEAA /* DSNetworkCache.m in Sources */ = {isa = PBXBuildFile; fileRef = D00A63562824C42300AFFEAA /* DSNetworkCache.m */; };
D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CB27FFCBAF00583D4E /* CWCarousel.m */; }; D01814D127FFCBAF00583D4E /* CWCarousel.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CB27FFCBAF00583D4E /* CWCarousel.m */; };
D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CD27FFCBAF00583D4E /* CWFlowLayout.m */; }; D01814D227FFCBAF00583D4E /* CWFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814CD27FFCBAF00583D4E /* CWFlowLayout.m */; };
...@@ -232,6 +234,10 @@ ...@@ -232,6 +234,10 @@
9B4D4A8254C6E2872914AB4D /* Pods-DreamSleep.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DreamSleep.beta.xcconfig"; path = "Target Support Files/Pods-DreamSleep/Pods-DreamSleep.beta.xcconfig"; sourceTree = "<group>"; }; 9B4D4A8254C6E2872914AB4D /* Pods-DreamSleep.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DreamSleep.beta.xcconfig"; path = "Target Support Files/Pods-DreamSleep/Pods-DreamSleep.beta.xcconfig"; sourceTree = "<group>"; };
D00291872816CD4500C0573B /* DsCacheUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DsCacheUtils.h; sourceTree = "<group>"; }; D00291872816CD4500C0573B /* DsCacheUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DsCacheUtils.h; sourceTree = "<group>"; };
D00291882816CD4500C0573B /* DsCacheUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DsCacheUtils.m; sourceTree = "<group>"; }; D00291882816CD4500C0573B /* DsCacheUtils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DsCacheUtils.m; sourceTree = "<group>"; };
D0031547284DAC0D00CFE94D /* RelaxBodyView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxBodyView.h; sourceTree = "<group>"; };
D0031548284DAC0D00CFE94D /* RelaxBodyView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxBodyView.m; sourceTree = "<group>"; };
D003154A284DF46F00CFE94D /* RelaxTrainCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainCell.h; sourceTree = "<group>"; };
D003154B284DF46F00CFE94D /* RelaxTrainCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainCell.m; sourceTree = "<group>"; };
D00A63552824C42300AFFEAA /* DSNetworkCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DSNetworkCache.h; sourceTree = "<group>"; }; D00A63552824C42300AFFEAA /* DSNetworkCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DSNetworkCache.h; sourceTree = "<group>"; };
D00A63562824C42300AFFEAA /* DSNetworkCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkCache.m; sourceTree = "<group>"; }; D00A63562824C42300AFFEAA /* DSNetworkCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DSNetworkCache.m; sourceTree = "<group>"; };
D01814CB27FFCBAF00583D4E /* CWCarousel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CWCarousel.m; sourceTree = "<group>"; }; D01814CB27FFCBAF00583D4E /* CWCarousel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CWCarousel.m; sourceTree = "<group>"; };
...@@ -808,6 +814,10 @@ ...@@ -808,6 +814,10 @@
D0D96FDE2848457900461839 /* RelaxTrainRequestModel.m */, D0D96FDE2848457900461839 /* RelaxTrainRequestModel.m */,
D0D96FE02848493700461839 /* RelaxTrainModel.h */, D0D96FE02848493700461839 /* RelaxTrainModel.h */,
D0D96FE12848493700461839 /* RelaxTrainModel.m */, D0D96FE12848493700461839 /* RelaxTrainModel.m */,
D0031547284DAC0D00CFE94D /* RelaxBodyView.h */,
D0031548284DAC0D00CFE94D /* RelaxBodyView.m */,
D003154A284DF46F00CFE94D /* RelaxTrainCell.h */,
D003154B284DF46F00CFE94D /* RelaxTrainCell.m */,
); );
path = AISleepModule; path = AISleepModule;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1747,6 +1757,7 @@ ...@@ -1747,6 +1757,7 @@
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */, D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */, D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */,
D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */, D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */,
D0031549284DAC0D00CFE94D /* RelaxBodyView.m in Sources */,
D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */, D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */,
D0D00199282C9402004EAFA1 /* NoiseView.m in Sources */, D0D00199282C9402004EAFA1 /* NoiseView.m in Sources */,
D062A0A128183FE000B4F48A /* FeedbackDetailController.m in Sources */, D062A0A128183FE000B4F48A /* FeedbackDetailController.m in Sources */,
...@@ -1839,6 +1850,7 @@ ...@@ -1839,6 +1850,7 @@
D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */, D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */,
D0878F4C280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m in Sources */, D0878F4C280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m in Sources */,
D0F80907280431100097899F /* UILabel+Extras.m in Sources */, D0F80907280431100097899F /* UILabel+Extras.m in Sources */,
D003154C284DF46F00CFE94D /* RelaxTrainCell.m in Sources */,
D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */, D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */,
D0AEFE822817DD1500230DC6 /* MyFeedListController.m in Sources */, D0AEFE822817DD1500230DC6 /* MyFeedListController.m in Sources */,
D055BEC828252D8200BC11A4 /* AudioCourseCell.m in Sources */, D055BEC828252D8200BC11A4 /* AudioCourseCell.m in Sources */,
...@@ -2064,7 +2076,7 @@ ...@@ -2064,7 +2076,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepDebug.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepDebug.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual; CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
EXCLUDED_ARCHS = ""; EXCLUDED_ARCHS = "";
...@@ -2134,7 +2146,7 @@ ...@@ -2134,7 +2146,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/DreamSleep.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
...@@ -2265,7 +2277,7 @@ ...@@ -2265,7 +2277,7 @@
CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepBeta.entitlements; CODE_SIGN_ENTITLEMENTS = DreamSleep/Basement/DSConfig/DreamSleepBeta.entitlements;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 5; CURRENT_PROJECT_VERSION = 6;
DEVELOPMENT_TEAM = 4NDZ6UX8PW; DEVELOPMENT_TEAM = 4NDZ6UX8PW;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = (
......
//
// RelaxBodyView.h
// DreamSleep
//
// Created by peter on 2022/6/6.
//
#import <UIKit/UIKit.h>
#import "RelaxTrainModel.h"
NS_ASSUME_NONNULL_BEGIN
@protocol RelaxBodyViewDelegate <NSObject>
- (void)updateNaviTitleAndBgImg:(RelaxTrainModel *)trainModel;
@end
/// 放松body主视图
@interface RelaxBodyView : UIView
@property (nonatomic, weak) id<RelaxBodyViewDelegate> delegate;
- (void)refreshData:(NSArray *)listArr currentIndex:(NSInteger)index;
/// 页面退出时停止音频播放
- (void)stopAudio;
@end
NS_ASSUME_NONNULL_END
//
// RelaxBodyView.m
// DreamSleep
//
// Created by peter on 2022/6/6.
//
#import "RelaxBodyView.h"
#import "RelaxTrainModel.h"
#import <FSAudioController.h>
#import "RelaxTrainCell.h"
@interface RelaxBodyView () <UIGestureRecognizerDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UIButton *playerBtn;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UISlider *sliderView;
@property (nonatomic, strong) UILabel *proLeftLb;
@property (nonatomic, strong) UILabel *proRightLb;
@property (nonatomic, strong) UILabel *tipsLab;
@property (nonatomic, strong) FSAudioStream *audioStream;
@property (nonatomic, strong) CADisplayLink *progressTimer;
@property (nonatomic, assign) BOOL isDraging;
@property (nonatomic, assign) FSAudioStreamState streamState;
@property (nonatomic, strong) UIView *relaxRecView;
@property (nonatomic, strong) UICollectionView *relaxCollectionView;
@property (nonatomic, strong) NSArray *relaxList;
@property (nonatomic, assign) NSInteger curIndex;
@end
@implementation RelaxBodyView {
UITapGestureRecognizer *_tapGesture;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.curIndex = 0;
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.layer.cornerRadius = 26.0;
self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
[self addSubview:self.playerBtn];
[self addSubview:self.titleLab];
[self addSubview:self.sliderView];
[self addSubview:self.proLeftLb];
[self addSubview:self.proRightLb];
[self addSubview:self.tipsLab];
[self addSubview:self.relaxRecView];
[self addSubview:self.relaxCollectionView];
[self.playerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self).offset(-45);
make.top.equalTo(self).offset(-35);
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(15);
make.top.equalTo(self).offset(40);
}];
[self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(38);
make.right.equalTo(self.mas_right).offset(-37);
make.height.equalTo(@15);
make.top.equalTo(self.titleLab.mas_bottom).offset(11);
}];
[self.proLeftLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.sliderView.mas_left);
make.top.equalTo(self.sliderView.mas_bottom).offset(6);
make.height.equalTo(@17);
make.width.equalTo(@100);
}];
[self.proRightLb mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.sliderView.mas_right);
make.top.equalTo(self.sliderView.mas_bottom).offset(6);
make.height.equalTo(@17);
make.width.equalTo(@100);
}];
[self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(15);
make.right.equalTo(self.mas_right).offset(-15);
make.top.equalTo(self.sliderView.mas_bottom).offset(43);
}];
[self.relaxRecView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(15);
make.right.equalTo(self).offset(-15);
make.top.equalTo(self.tipsLab.mas_bottom).offset(24);
make.height.equalTo(@22);
}];
[self.relaxCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.relaxRecView.mas_bottom).offset(17);
make.left.equalTo(self.relaxRecView);
make.right.equalTo(self);
make.bottom.equalTo(self).offset(-Bottom_SafeArea_Height);
}];
self.progressTimer = [CADisplayLink displayLinkWithTarget:[TimerProxy proxyWithTarget:self] selector:@selector(updateProgress)];
[self.progressTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
return self;
}
- (void)dealloc {
[self.progressTimer invalidate];
self.progressTimer = nil;
}
- (void)playControlAction:(UIButton *)sender {
if (self.streamState == kFsAudioStreamStopped) {
[self.audioStream play];
} else if (self.streamState == kFsAudioStreamPlaying) {
// 暂停播放
[self.audioStream pause];
} else if (self.streamState == kFsAudioStreamPaused) {
// 恢复播放
[self.audioStream pause];
}
}
#pragma mark - 解决按钮超出父视图区域无法点击
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == nil) {
CGPoint tempPoint = [self.playerBtn convertPoint:point fromView:self];
// 判断点击的点是否在按钮区域内
if (CGRectContainsPoint(self.playerBtn.bounds, tempPoint)) {
//返回按钮
return self.playerBtn;
}
}
return view;
}
- (void)updateProgress {
if (self.isDraging == YES) return;
FSStreamPosition cur = self.audioStream.currentTimePlayed;
FSStreamPosition end = self.audioStream.duration;
// 更新音频播放进度、音频当前播放时间、音频总时间
self.sliderView.value = cur.position;
self.proLeftLb.text = [NSString stringWithFormat:@"%02i:%02i", cur.minute, cur.second];
self.proRightLb.text = [NSString stringWithFormat:@"%02i:%02i", end.minute, end.second];
}
- (void)refreshData:(NSArray *)listArr currentIndex:(NSInteger)index {
if (listArr.count && index < listArr.count) {
self.curIndex = index;
RelaxTrainModel *relaxModel = listArr[index];
[self refreshTopData:relaxModel];
// self.titleLab.text = relaxModel.audio_name;
// NSString *audio_desc = [[NSString stringWithFormat:@"%@", relaxModel.audio_desc] stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
// self.tipsLab.height = [NSString getHeightWithText:audio_desc withFont:SysFont(14.0) withMaxWidth:kScreenWidth - 30];
// self.tipsLab.text = audio_desc;
//
// // 不是正在播放的状态需要先停止
// if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; }
// [self.audioStream playFromURL:[NSURL URLWithString:relaxModel.audio_url]];
self.relaxList = listArr;
[self.relaxCollectionView reloadData];
}
}
- (void)stopAudio {
if (self.streamState == kFsAudioStreamPlaying) {
[self.audioStream pause];
}
[self.audioStream stop];
}
- (void)refreshTopData:(RelaxTrainModel *)relaxModel {
if (self.delegate && [self.delegate respondsToSelector:@selector(updateNaviTitleAndBgImg:)]) {
[self.delegate updateNaviTitleAndBgImg:relaxModel];
}
self.titleLab.text = relaxModel.audio_name;
NSString *audio_desc = [[NSString stringWithFormat:@"%@", relaxModel.audio_desc] stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
self.tipsLab.height = [NSString getHeightWithText:audio_desc withFont:SysFont(14.0) withMaxWidth:kScreenWidth - 30];
self.tipsLab.text = audio_desc;
// 不是正在播放的状态需要先停止
if (self.audioStream.isPlaying == NO) { [self.audioStream stop]; }
[self.audioStream playFromURL:[NSURL URLWithString:relaxModel.audio_url]];
}
#pragma mark - UIGestureRecognizerDelegate
- (void)actionTapGesture:(UITapGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:self.sliderView];
float value = (self.sliderView.maximumValue - self.sliderView.minimumValue) * (touchPoint.x / self.sliderView.width);
[self.sliderView setValue:value animated:YES];
[self didSliderTouchEnded:value];
}
#pragma mark - 滑块事件
- (void)sliderValueChanged:(UISlider *)sender {
self.isDraging = YES;
}
- (void)sliderTouchDown:(UISlider *)sender {
_tapGesture.enabled = NO;
self.isDraging = YES;
}
- (void)sliderTouchUpInSide:(UISlider *)sender {
_tapGesture.enabled = YES;
[self didSliderTouchEnded:sender.value];
}
- (void)didSliderTouchEnded:(float)value {
self.isDraging = NO;
// 避免用户拖动进度条出现极值导致音频文件加载失败问题
if (value == 0) value = 0.001;
if (value == 1) value = 0.999;
FSStreamPosition pos = {0};
pos.position = value;
[self.audioStream seekToPosition:pos];
}
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.relaxList.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
RelaxTrainCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([RelaxTrainCell class]) forIndexPath:indexPath];
cell.trainModel = self.relaxList[indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (self.curIndex == indexPath.row) {
return;
}
self.curIndex = indexPath.row;
RelaxTrainModel *relaxModel = [self.relaxList objectAtIndex:indexPath.row];
[self refreshTopData:relaxModel];
}
#pragma mark - lazy
- (UIButton *)playerBtn {
if (!_playerBtn) {
_playerBtn = [UIButton new];
[_playerBtn addTarget:self action:@selector(playControlAction:) forControlEvents:UIControlEventTouchUpInside];
[_playerBtn dk_setBackgroundImage:DKImagePickerWithNames(@"audio_play_icon", @"audio_play_icon", @"audio_play_icon") forState:UIControlStateNormal];
[_playerBtn dk_setBackgroundImage:DKImagePickerWithNames(@"relax_pause", @"relax_pause", @"relax_pause") forState:UIControlStateSelected];
}
return _playerBtn;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel dkLabWithFont:BoldFont(16.0)];
}
return _titleLab;
}
- (UISlider *)sliderView {
if (!_sliderView) {
_sliderView = [UISlider new];
[_sliderView cornerRadius:2.0];
_sliderView.minimumTrackTintColor = BrandColor;
_sliderView.dk_maximumTrackTintColorPicker = DKColorPickerWithColors(ColorFromHex(0xE3E1E1), ColorFromHex(0x131724), DSWhite);
[_sliderView setThumbImage:[UIImage imageNamed:@"muse_slider_thumbImage"] forState:UIControlStateNormal];
[_sliderView addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[_sliderView addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
[_sliderView addTarget:self action:@selector(sliderTouchUpInSide:) forControlEvents:UIControlEventTouchUpInside];
// 为UISlider添加点击事件
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTapGesture:)];
_tapGesture.delegate = self;
[_sliderView addGestureRecognizer:_tapGesture];
}
return _sliderView;
}
- (UILabel *)tipsLab {
if (!_tipsLab) {
_tipsLab = [UILabel labWithFont:SysFont(14.0)];
_tipsLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_tipsLab.numberOfLines = 0;
_tipsLab.lineBreakMode = NSLineBreakByWordWrapping;
}
return _tipsLab;
}
- (UILabel *)proLeftLb {
if (!_proLeftLb) {
_proLeftLb = [UILabel labWithFont:SysFont(12)];
_proLeftLb.textAlignment = NSTextAlignmentLeft;
_proLeftLb.dk_textColorPicker = DKColorPickerWithColors(ColorFromHex(0xAAAAAA), ColorFromHex(0x5A6073), DSWhite);
}
return _proLeftLb;
}
- (UILabel *)proRightLb {
if (!_proRightLb) {
_proRightLb = [UILabel labWithFont:SysFont(12)];
_proRightLb.textAlignment = NSTextAlignmentRight;
_proRightLb.dk_textColorPicker = DKColorPickerWithColors(ColorFromHex(0xAAAAAA), ColorFromHex(0x5A6073), DSWhite);
}
return _proRightLb;
}
- (FSAudioStream *)audioStream {
if (_audioStream == nil) {
_audioStream = [[FSAudioStream alloc] init];
_audioStream.strictContentTypeChecking = NO;
_audioStream.defaultContentType = @"audio/mpeg";
WS(weakSelf);
[_audioStream setOnStateChange:^(FSAudioStreamState state) {
weakSelf.streamState = state;
weakSelf.playerBtn.selected = state == kFsAudioStreamPlaying;
[weakSelf.progressTimer setPaused:!(state == kFsAudioStreamPlaying)];
switch (state) {
case kFsAudioStreamRetrievingURL:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
DSLog(@"retrieving URL -- 检索文件");
break;
case kFsAudioStreamStopped:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
DSLog(@"kFsAudioStreamStopped --- 停止播放了");
break;
case kFsAudioStreamBuffering: {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
DSLog(@"buffering --- 缓存中");
break;
}
case kFsAudioStreamPaused:
DSLog(@"暂停了");
break;
case kFsAudioStreamSeeking:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
DSLog(@"kFsAudioStreamSeeking -- 快进 或者 快退");
break;
case kFsAudioStreamPlaying:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
DSLog(@"播放ing...");
break;
case kFsAudioStreamFailed:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
DSLog(@"音频文件加载失败");
break;
case kFsAudioStreamPlaybackCompleted:
break;
case kFsAudioStreamRetryingStarted:
DSLog(@"回放失败");
break;
case kFsAudioStreamRetryingSucceeded:
DSLog(@"重试成功");
break;
case kFsAudioStreamRetryingFailed:
DSLog(@"Failed to retry playback -- 重试失败");
break;
default:
break;
}
}];
}
return _audioStream;
}
- (UIView *)relaxRecView {
if (!_relaxRecView) {
_relaxRecView = [UIView new];
UIView *icon = [UIView new];
icon.backgroundColor = BrandColor;
[icon cornerRadius:2.0];
[_relaxRecView addSubview:icon];
UILabel *lab = [UILabel dkLabWithText:@"放松训练|推荐" font:BoldFont(16.0)];
[_relaxRecView addSubview:lab];
[icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_relaxRecView);
make.top.equalTo(_relaxRecView).offset(2);
make.bottom.equalTo(_relaxRecView).offset(-2);
make.width.equalTo(@4);
}];
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(icon.mas_right).offset(4);
make.top.bottom.equalTo(icon);
}];
}
return _relaxRecView;
}
- (UICollectionView *)relaxCollectionView {
if (!_relaxCollectionView) {
CGFloat width = 120;
CGFloat height = 150;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 15);
layout.itemSize = CGSizeMake(width, height);
layout.minimumLineSpacing = 12;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_relaxCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_relaxCollectionView.showsHorizontalScrollIndicator = NO;
_relaxCollectionView.delegate = self;
_relaxCollectionView.dataSource = self;
[_relaxCollectionView registerClass:[RelaxTrainCell class] forCellWithReuseIdentifier:NSStringFromClass([RelaxTrainCell class])];
_relaxCollectionView.backgroundColor = DSClearColor;
}
return _relaxCollectionView;
}
- (NSArray *)relaxList {
if (!_relaxList) {
_relaxList = [NSArray array];
}
return _relaxList;
}
@end
//
// RelaxTrainCell.h
// DreamSleep
//
// Created by peter on 2022/6/6.
//
#import <UIKit/UIKit.h>
#import "RelaxTrainModel.h"
NS_ASSUME_NONNULL_BEGIN
/// 放松训练音频cell
@interface RelaxTrainCell : UICollectionViewCell
@property (nonatomic, strong) RelaxTrainModel *trainModel;
@end
NS_ASSUME_NONNULL_END
//
// RelaxTrainCell.m
// DreamSleep
//
// Created by peter on 2022/6/6.
//
#import "RelaxTrainCell.h"
@interface RelaxTrainCell ()
// 主圆角图片
@property (nonatomic, strong) UIImageView *homeIV;
// 音频名标签
@property (nonatomic, strong) UILabel *audioNameLab;
@property (nonatomic, strong) UIImageView *recIcon;
@property (nonatomic, strong) UILabel *recLab;
@end
@implementation RelaxTrainCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self addSubview:self.homeIV];
[self addSubview:self.audioNameLab];
[self addSubview:self.recIcon];
[self addSubview:self.recLab];
[self.homeIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView);
make.left.equalTo(self);
make.width.height.equalTo(@(120));
}];
[self.audioNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.homeIV);
make.top.equalTo(self.homeIV.mas_bottom).offset(8);
}];
[self.recIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.homeIV);
make.left.equalTo(self.homeIV).offset(11);
}];
[self.recLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.recIcon);
}];
}
return self;
}
- (void)setTrainModel:(RelaxTrainModel *)trainModel {
_trainModel = trainModel;
[self.homeIV yy_setImageWithURL:[NSURL URLWithString:trainModel.bg_url] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.audioNameLab.text = trainModel.audio_name;
self.recIcon.hidden = [trainModel.is_recommend isEqualToString:@"0"];
self.recLab.hidden = [trainModel.is_recommend isEqualToString:@"0"];
}
#pragma mark - lazy
- (UIImageView *)homeIV {
if (!_homeIV) {
_homeIV = [UIImageView new];
_homeIV.contentMode = UIViewContentModeScaleAspectFill;
[_homeIV cornerRadius:12.0];
_homeIV.dk_alphaPicker = DKAlphaPickerWithAlphas(1.0, .5, .5);
}
return _homeIV;
}
- (UILabel *)audioNameLab {
if (!_audioNameLab) {
_audioNameLab = [UILabel labWithFont:SysFont(15)];
_audioNameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DSWhite);
}
return _audioNameLab;
}
- (UIImageView *)recIcon {
if (!_recIcon) {
_recIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"relax_rec_icon"]];
}
return _recIcon;
}
- (UILabel *)recLab {
if (!_recLab) {
_recLab = [UILabel labWithText:@"优选" textColor:DSWhite font:SysFont(12.0)];
_recLab.textAlignment = NSTextAlignmentCenter;
}
return _recLab;
}
@end
...@@ -7,11 +7,14 @@ ...@@ -7,11 +7,14 @@
#import "RelaxTrainController.h" #import "RelaxTrainController.h"
#import "RelaxTrainRequestModel.h" #import "RelaxTrainRequestModel.h"
#import "RelaxBodyView.h"
@interface RelaxTrainController () @interface RelaxTrainController () <RelaxBodyViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *bgIV; @property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UILabel *cusTitleLab; @property (nonatomic, strong) UILabel *cusTitleLab;
@property (nonatomic, strong) NSArray *listArr; @property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) UIScrollView *lucencyView;
@property (nonatomic, strong) RelaxBodyView *bodyView;
@end @end
@implementation RelaxTrainController @implementation RelaxTrainController
...@@ -19,45 +22,70 @@ ...@@ -19,45 +22,70 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.backgroundColor = DSWhite; self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.bgIV]; [self.view addSubview:self.bgIV];
[self.view addSubview:self.lucencyView];
[self.lucencyView addSubview:self.bodyView];
[self.view addSubview:self.dsNaviBar]; [self.view addSubview:self.dsNaviBar];
[self.view addSubview:self.dkBackBtn]; [self.view addSubview:self.dkBackBtn];
[self.dkBackBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"cus_back_icon", @"dk_cus_back_icon") forState:UIControlStateNormal]; [self.dkBackBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"cus_back_icon", @"dk_cus_back_icon") forState:UIControlStateNormal];
[self.view addSubview:self.cusTitleLab]; [self.view addSubview:self.cusTitleLab];
CGFloat iv_h = kScreenWidth*1233/1125.0;
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.equalTo(@(iv_h));
}];
[self.cusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.dsNaviBar);
make.bottom.equalTo(self.dsNaviBar).offset(-9);
}];
[self.lucencyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.equalTo(self.view);
}];
[RelaxTrainRequestModel queryRelaxAudioListWithCompletion:^(RelaxTrainRequestModel * _Nonnull requestModel) { [RelaxTrainRequestModel queryRelaxAudioListWithCompletion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
if (requestModel.trainAudioList.count) { if (requestModel.trainAudioList.count) {
self.listArr = requestModel.trainAudioList; self.listArr = requestModel.trainAudioList;
RelaxTrainModel *currentModel = requestModel.trainAudioList.firstObject; [self.bodyView refreshData:self.listArr currentIndex:0];
[self.bgIV setImageWithURL:[NSURL URLWithString:currentModel.bg_url] placeholderImage:[UIImage imageNamed:@"basicPlaceholder"]];
self.cusTitleLab.text = currentModel.audio_name;
} }
} }
}]; }];
#warning - 需要梳理业务逻辑
[RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) { [RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
}]; }];
CGFloat iv_h = kScreenWidth*1233/1125.0;
[self.bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.equalTo(@(iv_h));
}];
[self.cusTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.dsNaviBar);
make.bottom.equalTo(self.dsNaviBar).offset(-9);
}];
} }
#pragma mark - Actions #pragma mark - Actions
- (void)backAction { - (void)backAction {
[super backAction]; [super backAction];
[self.bodyView stopAudio];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
#pragma mark - RelaxBodyViewDelegate
- (void)updateNaviTitleAndBgImg:(RelaxTrainModel *)trainModel {
[self.bgIV setImageWithURL:[NSURL URLWithString:trainModel.bg_url] placeholderImage:[UIImage imageNamed:@"basicPlaceholder"]];
self.cusTitleLab.text = trainModel.audio_name;
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloat offset = scrollView.contentOffset.y;
NSLog(@"offset:%f", offset);
if (offset >= 35) {
self.dkBackBtn.hidden = YES;
}
if (offset <= -20) {
self.dkBackBtn.hidden = NO;
}
}
#pragma mark - lazy #pragma mark - lazy
- (UIImageView *)bgIV { - (UIImageView *)bgIV {
if (!_bgIV) { if (!_bgIV) {
...@@ -81,4 +109,29 @@ ...@@ -81,4 +109,29 @@
return _listArr; return _listArr;
} }
- (UIScrollView *)lucencyView {
if (!_lucencyView) {
_lucencyView = [UIScrollView new];
_lucencyView.showsVerticalScrollIndicator = NO;
_lucencyView.delegate = self;
CGFloat bodyTopMargin = 351;
CGFloat bodyH = 420 + Bottom_SafeArea_Height;
_lucencyView.contentSize = CGSizeMake(kScreenWidth, bodyH + bodyTopMargin);
}
return _lucencyView;
}
- (RelaxBodyView *)bodyView {
if (!_bodyView) {
_bodyView = [[RelaxBodyView alloc] initWithFrame:CGRectMake(0, 351, kScreenWidth, 420 + Bottom_SafeArea_Height)];
_bodyView.delegate = self;
}
return _bodyView;
}
#pragma mark - 设置状态栏文字颜色(重写父类)
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleDefault;
}
@end @end
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
if (!_verticalView) { if (!_verticalView) {
_verticalView = [UIView new]; _verticalView = [UIView new];
_verticalView.backgroundColor = BrandColor; _verticalView.backgroundColor = BrandColor;
[_verticalView cornerRadius:3]; [_verticalView cornerRadius:2.0];
} }
return _verticalView; return _verticalView;
} }
......
{
"images" : [
{
"filename" : "relax_pause.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "relax_pause@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "relax_pause@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "relax_rec_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "relax_rec_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "relax_rec_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!