RelaxTrainController.m
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// RelaxTrainController.m
// DreamSleep
//
// Created by peter on 2022/6/1.
//
#import "RelaxTrainController.h"
#import "RelaxTrainRequestModel.h"
#import "RelaxBodyView.h"
@interface RelaxTrainController () <RelaxBodyViewDelegate, UIScrollViewDelegate>
@property (nonatomic, strong) UIImageView *bgIV;
@property (nonatomic, strong) UILabel *cusTitleLab;
@property (nonatomic, strong) NSArray *listArr;
@property (nonatomic, strong) UIScrollView *lucencyView;
@property (nonatomic, strong) RelaxBodyView *bodyView;
@end
@implementation RelaxTrainController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.bgIV];
[self.view addSubview:self.lucencyView];
[self.lucencyView addSubview:self.bodyView];
[self.view addSubview:self.dsNaviBar];
[self.view addSubview:self.dkBackBtn];
[self.dkBackBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"cus_back_icon", @"dk_cus_back_icon") forState:UIControlStateNormal];
[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) {
if (requestModel.resCode == DSResCodeSuccess) {
if (requestModel.trainAudioList.count) {
self.listArr = requestModel.trainAudioList;
[self.bodyView refreshData:self.listArr currentIndex:0];
}
}
}];
#warning - 需要梳理业务逻辑
[RelaxTrainRequestModel userCurTaskStateWithParams:@{@"title":@"腹式呼吸放松法", @"step":@2} completion:^(RelaxTrainRequestModel * _Nonnull requestModel) {
}];
}
#pragma mark - Actions
- (void)backAction {
[super backAction];
[self.bodyView stopAudio];
[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
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [UIImageView new];
}
return _bgIV;
}
- (UILabel *)cusTitleLab {
if (!_cusTitleLab) {
_cusTitleLab = [UILabel labWithTextColor:MainTextColor font:BoldFont(18)];
_cusTitleLab.textAlignment = NSTextAlignmentCenter;
}
return _cusTitleLab;
}
- (NSArray *)listArr {
if (!_listArr) {
_listArr = [NSArray array];
}
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