Commit cc16cf97 cgx

首页白噪音初步完成

1 个父辈 6ebc1c44
正在显示 48 个修改的文件 包含 1078 行增加63 行删除
...@@ -119,6 +119,10 @@ ...@@ -119,6 +119,10 @@
D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3E282B89AD00EED7BE /* DSHomeView.m */; }; D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E3E282B89AD00EED7BE /* DSHomeView.m */; };
D0A72E42282B8BA600EED7BE /* CourseMusicCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E41282B8BA600EED7BE /* CourseMusicCell.m */; }; D0A72E42282B8BA600EED7BE /* CourseMusicCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A72E41282B8BA600EED7BE /* CourseMusicCell.m */; };
D0A750FC282DE21D00589B0E /* NoiseAudioCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */; }; D0A750FC282DE21D00589B0E /* NoiseAudioCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */; };
D0A75108282E2A8500589B0E /* NoisePlayBar.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A75107282E2A8500589B0E /* NoisePlayBar.m */; };
D0A7510E282E2FEF00589B0E /* NoisePlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A7510D282E2FEF00589B0E /* NoisePlayView.m */; };
D0A75111282E3D0D00589B0E /* NoisePlayCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A75110282E3D0D00589B0E /* NoisePlayCell.m */; };
D0A75115282E499200589B0E /* NoiseDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D0A75114282E499200589B0E /* NoiseDataManager.m */; };
D0AE1E3528281B6F008CEF27 /* TimerProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AE1E3428281B6F008CEF27 /* TimerProxy.m */; }; D0AE1E3528281B6F008CEF27 /* TimerProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AE1E3428281B6F008CEF27 /* TimerProxy.m */; };
D0AEFE79281781CF00230DC6 /* MyFeedModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AEFE78281781CF00230DC6 /* MyFeedModel.m */; }; D0AEFE79281781CF00230DC6 /* MyFeedModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AEFE78281781CF00230DC6 /* MyFeedModel.m */; };
D0AEFE7C2817D13400230DC6 /* UITableViewCell+CardRadius.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AEFE7A2817D13400230DC6 /* UITableViewCell+CardRadius.m */; }; D0AEFE7C2817D13400230DC6 /* UITableViewCell+CardRadius.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AEFE7A2817D13400230DC6 /* UITableViewCell+CardRadius.m */; };
...@@ -399,6 +403,15 @@ ...@@ -399,6 +403,15 @@
D0A72E41282B8BA600EED7BE /* CourseMusicCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CourseMusicCell.m; sourceTree = "<group>"; }; D0A72E41282B8BA600EED7BE /* CourseMusicCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CourseMusicCell.m; sourceTree = "<group>"; };
D0A750FA282DE21D00589B0E /* NoiseAudioCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoiseAudioCell.h; sourceTree = "<group>"; }; D0A750FA282DE21D00589B0E /* NoiseAudioCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoiseAudioCell.h; sourceTree = "<group>"; };
D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoiseAudioCell.m; sourceTree = "<group>"; }; D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoiseAudioCell.m; sourceTree = "<group>"; };
D0A75106282E2A8500589B0E /* NoisePlayBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NoisePlayBar.h; sourceTree = "<group>"; };
D0A75107282E2A8500589B0E /* NoisePlayBar.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NoisePlayBar.m; sourceTree = "<group>"; };
D0A7510C282E2FEF00589B0E /* NoisePlayView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoisePlayView.h; sourceTree = "<group>"; };
D0A7510D282E2FEF00589B0E /* NoisePlayView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoisePlayView.m; sourceTree = "<group>"; };
D0A7510F282E3D0D00589B0E /* NoisePlayCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoisePlayCell.h; sourceTree = "<group>"; };
D0A75110282E3D0D00589B0E /* NoisePlayCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoisePlayCell.m; sourceTree = "<group>"; };
D0A75112282E493D00589B0E /* Singleton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Singleton.h; sourceTree = "<group>"; };
D0A75113282E499200589B0E /* NoiseDataManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoiseDataManager.h; sourceTree = "<group>"; };
D0A75114282E499200589B0E /* NoiseDataManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NoiseDataManager.m; sourceTree = "<group>"; };
D0AE1E3328281B6F008CEF27 /* TimerProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TimerProxy.h; sourceTree = "<group>"; }; D0AE1E3328281B6F008CEF27 /* TimerProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TimerProxy.h; sourceTree = "<group>"; };
D0AE1E3428281B6F008CEF27 /* TimerProxy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TimerProxy.m; sourceTree = "<group>"; }; D0AE1E3428281B6F008CEF27 /* TimerProxy.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TimerProxy.m; sourceTree = "<group>"; };
D0AEFE77281781CF00230DC6 /* MyFeedModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyFeedModel.h; sourceTree = "<group>"; }; D0AEFE77281781CF00230DC6 /* MyFeedModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MyFeedModel.h; sourceTree = "<group>"; };
...@@ -1010,6 +1023,14 @@ ...@@ -1010,6 +1023,14 @@
D0D00198282C9402004EAFA1 /* NoiseView.m */, D0D00198282C9402004EAFA1 /* NoiseView.m */,
D0A750FA282DE21D00589B0E /* NoiseAudioCell.h */, D0A750FA282DE21D00589B0E /* NoiseAudioCell.h */,
D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */, D0A750FB282DE21D00589B0E /* NoiseAudioCell.m */,
D0A75106282E2A8500589B0E /* NoisePlayBar.h */,
D0A75107282E2A8500589B0E /* NoisePlayBar.m */,
D0A7510C282E2FEF00589B0E /* NoisePlayView.h */,
D0A7510D282E2FEF00589B0E /* NoisePlayView.m */,
D0A7510F282E3D0D00589B0E /* NoisePlayCell.h */,
D0A75110282E3D0D00589B0E /* NoisePlayCell.m */,
D0A75113282E499200589B0E /* NoiseDataManager.h */,
D0A75114282E499200589B0E /* NoiseDataManager.m */,
); );
path = WhiteNoise; path = WhiteNoise;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1060,6 +1081,7 @@ ...@@ -1060,6 +1081,7 @@
D0B5ECD927F2F410003EDFE3 /* Utils */ = { D0B5ECD927F2F410003EDFE3 /* Utils */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D0A75112282E493D00589B0E /* Singleton.h */,
D0AE1E3328281B6F008CEF27 /* TimerProxy.h */, D0AE1E3328281B6F008CEF27 /* TimerProxy.h */,
D0AE1E3428281B6F008CEF27 /* TimerProxy.m */, D0AE1E3428281B6F008CEF27 /* TimerProxy.m */,
D0C50B4427FD66FB00DC68F0 /* DSConstUtil.h */, D0C50B4427FD66FB00DC68F0 /* DSConstUtil.h */,
...@@ -1602,6 +1624,7 @@ ...@@ -1602,6 +1624,7 @@
D03AE82B281A9010001C0726 /* MyFeedDetailModel.m in Sources */, D03AE82B281A9010001C0726 /* MyFeedDetailModel.m in Sources */,
D0A750FC282DE21D00589B0E /* NoiseAudioCell.m in Sources */, D0A750FC282DE21D00589B0E /* NoiseAudioCell.m in Sources */,
D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */, D0C09EE028007E5F00709D4C /* BreatheController.m in Sources */,
D0A75108282E2A8500589B0E /* NoisePlayBar.m in Sources */,
D0C50B4627FD66FB00DC68F0 /* DSConstUtil.m in Sources */, D0C50B4627FD66FB00DC68F0 /* DSConstUtil.m in Sources */,
D08F79DC281A1838000D99DD /* TZProgressView.m in Sources */, D08F79DC281A1838000D99DD /* TZProgressView.m in Sources */,
D01BD428282C003900BA86B3 /* NoiseTypeModel.m in Sources */, D01BD428282C003900BA86B3 /* NoiseTypeModel.m in Sources */,
...@@ -1610,6 +1633,7 @@ ...@@ -1610,6 +1633,7 @@
D07A4B2D280EA73B00BA0EC0 /* UserInfoView.m in Sources */, D07A4B2D280EA73B00BA0EC0 /* UserInfoView.m in Sources */,
D0878F48280BD18F005F1B7F /* LoginView.m in Sources */, D0878F48280BD18F005F1B7F /* LoginView.m in Sources */,
D08F79D4281A1838000D99DD /* TZImageCropManager.m in Sources */, D08F79D4281A1838000D99DD /* TZImageCropManager.m in Sources */,
D0A75111282E3D0D00589B0E /* NoisePlayCell.m in Sources */,
D0E660052807D02C006562F2 /* UserRequestModel.m in Sources */, D0E660052807D02C006562F2 /* UserRequestModel.m in Sources */,
D0F82286280C44D10039F586 /* SetTableView.m in Sources */, D0F82286280C44D10039F586 /* SetTableView.m in Sources */,
D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */, D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */,
...@@ -1659,6 +1683,7 @@ ...@@ -1659,6 +1683,7 @@
D0B5ECC827F2E97A003EDFE3 /* MacroFuncUtil.m in Sources */, D0B5ECC827F2E97A003EDFE3 /* MacroFuncUtil.m in Sources */,
D055BEB928250D3400BC11A4 /* CourseCollectionCell.m in Sources */, D055BEB928250D3400BC11A4 /* CourseCollectionCell.m in Sources */,
D01814E227FFDBB800583D4E /* HomeHeaderView.m in Sources */, D01814E227FFDBB800583D4E /* HomeHeaderView.m in Sources */,
D0A75115282E499200589B0E /* NoiseDataManager.m in Sources */,
D055BEBC28250E8F00BC11A4 /* CourseModel.m in Sources */, D055BEBC28250E8F00BC11A4 /* CourseModel.m in Sources */,
D09BF33A280E94E300E5F06C /* LoginUtils.m in Sources */, D09BF33A280E94E300E5F06C /* LoginUtils.m in Sources */,
D0F808F52803D4E70097899F /* Track.m in Sources */, D0F808F52803D4E70097899F /* Track.m in Sources */,
...@@ -1683,6 +1708,7 @@ ...@@ -1683,6 +1708,7 @@
D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */, D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */,
D01814E8280020F900583D4E /* CWPageControl.m in Sources */, D01814E8280020F900583D4E /* CWPageControl.m in Sources */,
D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */, D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */,
D0A7510E282E2FEF00589B0E /* NoisePlayView.m in Sources */,
D08F79DD281A1838000D99DD /* TZImageManager.m in Sources */, D08F79DD281A1838000D99DD /* TZImageManager.m in Sources */,
D0506B1828054ECD00229278 /* SafeHelperCollectionView.m in Sources */, D0506B1828054ECD00229278 /* SafeHelperCollectionView.m in Sources */,
D04B3DC327F6F9390022F8DF /* HomeViewController.m in Sources */, D04B3DC327F6F9390022F8DF /* HomeViewController.m in Sources */,
......
...@@ -43,5 +43,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -43,5 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
// 添加遮罩 // 添加遮罩
- (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius; - (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius;
- (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -131,4 +131,12 @@ ...@@ -131,4 +131,12 @@
maskView.layer.mask = maskLayer; maskView.layer.mask = maskLayer;
} }
- (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:rectCorner cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = path.CGPath;
self.layer.mask = maskLayer;
}
@end @end
...@@ -40,4 +40,6 @@ ...@@ -40,4 +40,6 @@
#import "TimerProxy.h" #import "TimerProxy.h"
#import "Singleton.h"
#endif /* PrefixHeader_pch */ #endif /* PrefixHeader_pch */
//1、宏定义单例类.h文件,(name)代表传入的参数,##连接参数的
#define SingletonH(name) + (instancetype)shared##name;
//2、条件编译,ARC和MRC混编
//2.1 ARC编译环境下运行以下代码:
#if __has_feature(objc_arc)
//宏定义单例类.m文件,宏文件最后一行不能加"\"
#define SingletonM(name) \
static id _instance; \
\
+ (id)allocWithZone:(struct _NSZone *)zone{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
\
+ (instancetype)shared##name{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
} \
\
- (id)copyWithZone:(NSZone *)zone{ \
return _instance; \
}
//2.2 MRC编译环境下运行以下代码:
#else
#define SingletonM(name) \
static id _instance; \
\
+ (id)allocWithZone:(struct _NSZone *)zone{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \
\
+ (instancetype)shared##name{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[self alloc] init]; \
}); \
return _instance; \
} \
\
- (id)copyWithZone:(NSZone *)zone{ \
return _instance; \
} \
\
- (oneway void)release{} \
- (id)retain{return self;} \
- (NSUInteger)retainCount{return 1;} \
- (id)autorelease{return self;}
#endif
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
<scenes> <scenes>
...@@ -19,7 +21,7 @@ ...@@ -19,7 +21,7 @@
</navigationBar> </navigationBar>
<nil name="viewControllers"/> <nil name="viewControllers"/>
<connections> <connections>
<segue destination="M3U-9a-TZh" kind="relationship" relationship="rootViewController" id="7Ny-Sf-Eck"/> <segue destination="eRh-HX-KPC" kind="relationship" relationship="rootViewController" id="Xr2-Oc-BOL"/>
</connections> </connections>
</navigationController> </navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dv3-jw-tTl" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="dv3-jw-tTl" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
...@@ -55,9 +57,28 @@ ...@@ -55,9 +57,28 @@
</objects> </objects>
<point key="canvasLocation" x="2390" y="-437"/> <point key="canvasLocation" x="2390" y="-437"/>
</scene> </scene>
<!--Home View Controller-->
<scene sceneID="9uz-sO-q7v">
<objects>
<viewController id="eRh-HX-KPC" customClass="HomeViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="WyL-5a-l8Y">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="rii-Dg-Ow2"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<navigationItem key="navigationItem" id="Q2J-n6-azR"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sPS-Xw-nyE" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="3125" y="-437"/>
</scene>
</scenes> </scenes>
<resources> <resources>
<image name="home" width="25" height="25"/> <image name="home" width="25" height="25"/>
<image name="home_selected" width="25" height="25"/> <image name="home_selected" width="25" height="25"/>
<systemColor name="systemBackgroundColor">
<color red="0.0" green="0.46000000000000002" blue="0.89000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources> </resources>
</document> </document>
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface HomeViewController : UITableViewController @interface HomeViewController : UIViewController
@end @end
......
...@@ -14,18 +14,16 @@ ...@@ -14,18 +14,16 @@
#import "ThreeMinuteController.h" #import "ThreeMinuteController.h"
#import "SafeSleepRequestModel.h" #import "SafeSleepRequestModel.h"
#import "WhiteNoiseRequestModel.h" #import "WhiteNoiseRequestModel.h"
#import "NoisePlayBar.h"
@interface HomeViewController () @interface HomeViewController ()
@property (nonatomic, strong) DSHomeView *homeTV; @property (nonatomic, strong) DSHomeView *homeTV;
@property (nonatomic, strong) RescuePlanView *rescuePlanView; @property (nonatomic, strong) RescuePlanView *rescuePlanView;
@property (nonatomic, strong) NoisePlayBar *noisePlayBar;
@end @end
@implementation HomeViewController @implementation HomeViewController
- (void)loadView {
self.view = self.homeTV;
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
...@@ -34,6 +32,16 @@ ...@@ -34,6 +32,16 @@
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftLab]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftLab];
self.navigationItem.leftBarButtonItem = leftItem; self.navigationItem.leftBarButtonItem = leftItem;
[self.view addSubview:self.homeTV];
[self.view addSubview:self.noisePlayBar];
[self.noisePlayBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(15);
make.right.equalTo(self.view).offset(-15);
make.bottom.equalTo(self.view).offset(-15);
make.height.equalTo(@50);
}];
self.edgesForExtendedLayout = UIRectEdgeNone;
if ([LoginUtils getUserLoginData]) { if ([LoginUtils getUserLoginData]) {
// 自动登录请求(调用时机) // 自动登录请求(调用时机)
[UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {}]; [UserRequestModel autoLoginRequestWithCompletion:^(UserRequestModel * _Nonnull requestModel) {}];
...@@ -50,14 +58,6 @@ ...@@ -50,14 +58,6 @@
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdate) name:NeedUpdateHomePage object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdate) name:NeedUpdateHomePage object:nil];
} }
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
self.homeTV.frame = CGRectMake(0, kTopHeight(0), kScreenWidth, kScreenHeight - kTopHeight(0) - kTabBarHeight);
});
}
- (void)dealloc { - (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateHomePage object:nil];
} }
...@@ -197,8 +197,16 @@ ...@@ -197,8 +197,16 @@
- (DSHomeView *)homeTV { - (DSHomeView *)homeTV {
if (!_homeTV) { if (!_homeTV) {
_homeTV = [[DSHomeView alloc] init]; _homeTV = [[DSHomeView alloc] init];
_homeTV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} }
return _homeTV; return _homeTV;
} }
- (NoisePlayBar *)noisePlayBar {
if (!_noisePlayBar) {
_noisePlayBar = [NoisePlayBar new];
}
return _noisePlayBar;
}
@end @end
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
@implementation DSHomeView @implementation DSHomeView
- (instancetype)init { - (instancetype)init {
if (self = [super initWithFrame:CGRectMake(0, kTopHeight(0), kScreenWidth, kScreenHeight - kTopHeight(0) - kTabBarHeight) style:UITableViewStylePlain]) { if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTopHeight(0) - kTabBarHeight) style:UITableViewStylePlain]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG); self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.separatorStyle = UITableViewCellSeparatorStyleNone; self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsVerticalScrollIndicator = NO; self.showsVerticalScrollIndicator = NO;
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
} else if (indexPath.row == 1) { } else if (indexPath.row == 1) {
height = 206; height = 206;
} else if (indexPath.row == 2) { } else if (indexPath.row == 2) {
height = 68 + 40 + 327; height = 68 + 40 + 327 + 70;
} }
return height; return height;
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#pragma mark - Actions #pragma mark - Actions
- (void)timerSetting:(UIButton *)sender { - (void)timerSetting:(UIButton *)sender {
DSLog(@"timerSetting"); [[NSNotificationCenter defaultCenter] postNotificationName:@"timingDidClickNoti" object:nil];
} }
#pragma mark - lazy #pragma mark - lazy
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <FSAudioController.h>
#import "NoiseDataManager.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
...@@ -23,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -23,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *audio_url; @property (nonatomic, copy) NSString *audio_url;
// 是否推荐(默认0:不推荐,1:推荐) // 是否推荐(默认0:不推荐,1:推荐)
@property (nonatomic, copy) NSString *is_recommend; @property (nonatomic, copy) NSString *is_recommend;
/// 播放器
@property (nonatomic, strong) FSAudioStream *audioStream;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
//
// NoiseDataManager.h
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/// 音频数据共享单例对象
@interface NoiseDataManager : NSObject
SingletonH(NoiseDataManager)
/// 选中的白噪音数据
@property (nonatomic, strong) NSArray *playList;
/// 用于存储播放流对象
@property (nonatomic, strong) NSArray *audioStreamArr;
@end
NS_ASSUME_NONNULL_END
//
// NoiseDataManager.m
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import "NoiseDataManager.h"
@implementation NoiseDataManager
SingletonM(NoiseDataManager)
- (void)setPlayList:(NSArray *)playList {
_playList = playList;
[[NSNotificationCenter defaultCenter] postNotificationName:@"updatePlistNoti" object:nil userInfo:@{@"playList":self.playList}];
}
- (void)setAudioStreamArr:(NSArray *)audioStreamArr {
_audioStreamArr = audioStreamArr;
}
@end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "NoiseListController.h" #import "NoiseListController.h"
#import "WhiteNoiseRequestModel.h" #import "WhiteNoiseRequestModel.h"
#import "NoiseAudioCell.h" #import "NoiseAudioCell.h"
#import "NoiseDataManager.h"
@interface NoiseListController () <UICollectionViewDelegate, UICollectionViewDataSource> @interface NoiseListController () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *noiseAudioView; @property (nonatomic, strong) UICollectionView *noiseAudioView;
...@@ -28,9 +29,9 @@ ...@@ -28,9 +29,9 @@
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.noiseAudioView]; [self.view addSubview:self.noiseAudioView];
self.view.backgroundColor = _typeID == 32 ? BrandColor : DSRed;
[WhiteNoiseRequestModel queryRelaxWhiteNoiseAudiosWithTypeID:_typeID completion:^(WhiteNoiseRequestModel * _Nonnull requestModel) { [WhiteNoiseRequestModel queryRelaxWhiteNoiseAudiosWithTypeID:_typeID completion:^(WhiteNoiseRequestModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
self.noiseAudioArr = requestModel.noiseAudioArr; self.noiseAudioArr = requestModel.noiseAudioArr;
...@@ -51,9 +52,36 @@ ...@@ -51,9 +52,36 @@
} }
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// NoiseAudioModel *model = [self.noiseAudioArr objectAtIndex:indexPath.row]; NoiseAudioModel *model = [self.noiseAudioArr objectAtIndex:indexPath.row];
NoiseAudioCell *cell = (NoiseAudioCell *)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]]; NoiseAudioCell *cell = (NoiseAudioCell *)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
cell.model = model;
NSArray *playList = [NoiseDataManager sharedNoiseDataManager].playList;
NSMutableArray *selectedDataArr = [NSMutableArray arrayWithArray:playList];
// 白噪音未被选择则添加到播放列表
if (cell.audioIV.selected == NO) {
if (selectedDataArr.count >= 8) {
[DSProgressHUD showToast:@"音频最多同时播放8个"];
return;
}
// 添加播放器
FSAudioStream *audioStream = [[FSAudioStream alloc] init];
audioStream.strictContentTypeChecking = NO;
audioStream.defaultContentType = @"audio/mpeg";
model.audioStream = audioStream;
[selectedDataArr addObject:cell];
playList = [selectedDataArr copy];
} else {
// 白噪音已经选择了则从播放列表移除
if (model.audioStream) {
[model.audioStream stop];
}
[selectedDataArr removeObject:cell];
}
cell.audioIV.selected = !cell.audioIV.selected; cell.audioIV.selected = !cell.audioIV.selected;
[NoiseDataManager sharedNoiseDataManager].playList = [selectedDataArr copy];
} }
#pragma mark - lazy #pragma mark - lazy
......
//
// NoisePlayBar.h
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 首页白噪音播放悬浮条
@interface NoisePlayBar : UIView
@end
NS_ASSUME_NONNULL_END
//
// NoisePlayBar.m
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import "NoisePlayBar.h"
#import "NoiseAudioModel.h"
#import "NoisePlayView.h"
#import "NoiseAudioCell.h"
#import "TimingView.h"
@interface NoisePlayBar ()
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *topIV;
@property (nonatomic, strong) UILabel *audioLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIButton *playBtn;
@property (nonatomic, strong) NoisePlayView *noisePlayView;
@property (nonatomic, strong) TimingView *timingView;
@property (nonatomic, assign) NSInteger minuteIndex;
@property (nonatomic, assign) NSInteger countTime;
@property (nonatomic, assign) NSInteger totalTime;
@property (nonatomic, strong) NSTimer *timer;
@end
@implementation NoisePlayBar
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self cornerRadius:12.0];
self.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
self.hidden = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAudioListView)];
[self addGestureRecognizer:tap];
[self addSubview:self.topIV];
[self addSubview:self.audioLab];
[self addSubview:self.timeLab];
[self addSubview:self.playBtn];
[self.topIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self);
make.centerY.equalTo(self);
make.height.width.equalTo(@30);
}];
[self.audioLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.topIV.mas_right).offset(12);
make.top.bottom.equalTo(self);
make.right.equalTo(self.timeLab.mas_left).offset(-12);
}];
[self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.equalTo(self);
make.right.equalTo(self.playBtn.mas_left).offset(-12);
make.width.equalTo(@100);
}];
[self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self);
make.right.equalTo(self).offset(-8);
make.height.width.equalTo(@35);
}];
self.minuteIndex = 0;
self.countTime = 60;
// 添加对单例对象播放列表变化通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePlist:) name:@"updatePlistNoti" object:nil];
// 监听定时按钮被点击事件通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openTimingView) name:@"timingDidClickNoti" object:nil];
}
return self;
}
- (void)updatePlist:(NSNotification *)noti {
NSArray *playList = noti.userInfo[@"playList"];
if (playList) {
WS(weakSelf);
self.hidden = !(playList.count > 0);
NSMutableString *mStr = [NSMutableString string];
for (int i = 0; i < playList.count; i++) {
NoiseAudioCell *audioCell = playList[i];
__weak FSAudioStream *audioStream = audioCell.model.audioStream;
audioStream.onStateChange = ^(FSAudioStreamState state) {
weakSelf.playBtn.selected = state == kFsAudioStreamPlaying;
// 如果播放完成则重复播放
if (state == kFsAudioStreamPlaybackCompleted) {
[audioStream play];
}
};
[mStr appendFormat:@"%@%@", audioCell.model.audio_name, (i == playList.count - 1) ? @"" : @","];
[audioCell.model.audioStream playFromURL:[NSURL URLWithString:audioCell.model.audio_url]];
}
self.audioLab.text = [mStr copy];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updatePlistNoti" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"timingDidClickNoti" object:nil];
[_timer invalidate];
_timer = nil;
[_timingView removeFromSuperview];
_timingView = nil;
}
- (void)openTimingView {
[self.timingView display];
}
- (void)showAudioListView {
[self.noisePlayView show];
}
- (void)playNoiseAudio:(UIButton *)sender {
sender.selected = !sender.selected;
NSArray *playList = [NoiseDataManager sharedNoiseDataManager].playList;
for (int i = 0; i < playList.count; i++) {
NoiseAudioCell *audioCell = playList[i];
[audioCell.model.audioStream stop];
if (sender.selected) {
[audioCell.model.audioStream playFromURL:[NSURL URLWithString:audioCell.model.audio_url]];
}
}
}
- (UIImageView *)topIV {
if (!_topIV) {
_topIV = [UIImageView new];
[_topIV dk_setImagePicker:DKImagePickerWithNames(@"noise_up", @"dk_noise_up", @"dk_noise_up")];
}
return _topIV;
}
- (UILabel *)audioLab {
if (!_audioLab) {
_audioLab = [UILabel labWithFont:SysFont(15.0)];
_audioLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHex(0xE8E9E9), DSWhite);
_audioLab.textAlignment = NSTextAlignmentLeft;
}
return _audioLab;
}
- (UILabel *)timeLab {
if (!_timeLab) {
_timeLab = [UILabel labWithFont:SysFont(15.0)];
_timeLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHex(0xE8E9E9), DSWhite);
_timeLab.textAlignment = NSTextAlignmentRight;
}
return _timeLab;
}
- (UIButton *)playBtn {
if (!_playBtn) {
_playBtn = [UIButton new];
[_playBtn addTarget:self action:@selector(playNoiseAudio:) forControlEvents:UIControlEventTouchUpInside];
[_playBtn dk_setBackgroundImage:DKImagePickerWithNames(@"audio_play_icon", @"dk_audio_play_icon", @"dk_audio_play_icon") forState:UIControlStateNormal];
[_playBtn dk_setBackgroundImage:DKImagePickerWithNames(@"audio_pause", @"dk_audio_pause", @"dk_audio_pause") forState:UIControlStateSelected];
}
return _playBtn;
}
- (NoisePlayView *)noisePlayView {
if (!_noisePlayView) {
_noisePlayView = [NoisePlayView new];
}
return _noisePlayView;
}
- (TimingView *)timingView {
if (!_timingView) {
WS(weakSelf);
_timingView = [[TimingView alloc] initWithSureBlock:^(NSInteger index, NSArray * _Nonnull minuteDatas) {
weakSelf.minuteIndex = index;
weakSelf.countTime = 60 * [minuteDatas[index] intValue];
weakSelf.totalTime = 60 * [minuteDatas[index] intValue];
[weakSelf.timer setFireDate:[NSDate date]];
}];
}
return _timingView;
}
- (NSTimer *)timer {
if (!_timer) {
WS(weakSelf);
_timer = [NSTimer timerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
// 暂停播放
if (weakSelf.countTime == 0) {
[weakSelf.timer setFireDate:[NSDate distantFuture]];
NSArray *playList = [NoiseDataManager sharedNoiseDataManager].playList;
if (playList) {
for (NoiseAudioCell *audioCell in playList) {
FSAudioStream *audioStream = audioCell.model.audioStream;
if (audioStream.isPlaying) {
[audioStream pause];
}
}
}
weakSelf.timeLab.text = @"";
return;
}
weakSelf.countTime--;
NSString *countDownStr = [weakSelf formattimewithtimeinterval:weakSelf.countTime];
NSString *totalTimeStr = [weakSelf formattimewithtimeinterval:weakSelf.totalTime];
weakSelf.timeLab.text = [NSString stringWithFormat:@"%@/%@",countDownStr, totalTimeStr];
}];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
}
return _timer;
}
#pragma mark - others
- (NSString *)formattimewithtimeinterval:(NSTimeInterval)timeinterval {
int minute = 0, hour = 0, secend = timeinterval;
minute = (secend % 3600)/60;
hour = secend / 3600;
secend = secend % 60;
if (hour == 0) {
return [NSString stringWithFormat:@"%02d:%02d", minute, secend];
} else if (minute == 0){
return [NSString stringWithFormat:@"%02d",secend];
} else {
return [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minute, secend];
}
}
@end
//
// NoisePlayCell.h
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import <UIKit/UIKit.h>
#import "NoiseAudioModel.h"
NS_ASSUME_NONNULL_BEGIN
@protocol NoisePlayCellDelegate <NSObject>
/// 删除音频
/// @param indexPath indexPath
- (void)didRemoveItem:(NSIndexPath *)indexPath;
/// 控制音量大小
/// @param volume 音量值
- (void)didSetVolume:(float)volume indexPath:(NSIndexPath *)indexPath;
@end
@interface NoisePlayCell : UITableViewCell
@property (nonatomic, weak) id<NoisePlayCellDelegate> delegate;
@property (nonatomic, strong) NoiseAudioModel *model;
@property (nonatomic, strong) NSIndexPath *indexPath;
@end
NS_ASSUME_NONNULL_END
//
// NoisePlayCell.m
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import "NoisePlayCell.h"
@interface NoisePlayCell ()
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *audioIcon;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UIImageView *volumeIcon;
@property (nonatomic, strong) UISlider *volumeSlider;
@property (nonatomic, strong) UIButton *deleteBtn;
@end
@implementation NoisePlayCell {
UITapGestureRecognizer *_tapGesture;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.bgView];
[self.bgView addSubview:self.audioIcon];
[self.bgView addSubview:self.nameLab];
[self.bgView addSubview:self.volumeIcon];
[self.bgView addSubview:self.volumeSlider];
[self.bgView addSubview:self.deleteBtn];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(15);
make.right.equalTo(self.contentView).offset(-15);
make.top.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).offset(-12);
}];
[self.audioIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(self.bgView).offset(8);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.audioIcon);
make.top.equalTo(self.audioIcon.mas_bottom).offset(2);
make.bottom.equalTo(self.bgView).offset(-8);
}];
[self.volumeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.audioIcon.mas_right).offset(12);
make.top.equalTo(self.bgView).offset(17);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self.volumeSlider mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.volumeIcon.mas_right).offset(8);
make.right.equalTo(self.deleteBtn.mas_left).offset(-8);
make.height.equalTo(@15);
make.centerY.equalTo(self.volumeIcon);
}];
[self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgView).offset(17);
make.size.mas_equalTo(CGSizeMake(30, 30));
make.right.equalTo(self.bgView).offset(-8);
}];
}
return self;
}
- (void)setModel:(NoiseAudioModel *)model {
_model = model;
[self.audioIcon yy_setImageWithURL:[NSURL URLWithString:model.audio_pic] placeholder:[UIImage imageNamed:@"basicPlaceholder"]];
self.nameLab.text = model.audio_name;
self.volumeSlider.value = model.audioStream.volume;
}
- (void)setIndexPath:(NSIndexPath *)indexPath {
_indexPath = indexPath;
}
- (void)deleteAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(didRemoveItem:)]) {
[self.delegate didRemoveItem:self.indexPath];
}
}
#pragma mark - 滑块事件
- (void)sliderValueChanged:(UISlider *)sender {
[self.volumeSlider setValue:sender.value animated:YES];
if (self.delegate && [self.delegate respondsToSelector:@selector(didSetVolume:indexPath:)]) {
[self.delegate didSetVolume:sender.value indexPath:self.indexPath];
}
}
- (void)sliderTouchDown:(UISlider *)sender {
_tapGesture.enabled = NO;
}
- (void)sliderTouchUpInSide:(UISlider *)sender {
_tapGesture.enabled = YES;
}
#pragma mark - UIGestureRecognizerDelegate
- (void)actionTapGesture:(UITapGestureRecognizer *)sender {
CGPoint touchPoint = [sender locationInView:self.volumeSlider];
float value = (self.volumeSlider.maximumValue - self.volumeSlider.minimumValue) * (touchPoint.x / self.volumeSlider.width);
[self.volumeSlider setValue:value animated:YES];
if (self.delegate && [self.delegate respondsToSelector:@selector(didSetVolume:indexPath:)]) {
[self.delegate didSetVolume:value indexPath:self.indexPath];
}
}
#pragma mark - lazy
- (UIView *)bgView {
if (!_bgView) {
_bgView = [UIView new];
_bgView.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, ColorFromHex(0x1F263F), DSWhite);
[_bgView cornerRadius:12.0];
}
return _bgView;
}
- (UIImageView *)audioIcon {
if (!_audioIcon) {
_audioIcon = [UIImageView new];
}
return _audioIcon;
}
- (UILabel *)nameLab {
if (!_nameLab) {
_nameLab = [UILabel labWithFont:SysFont(12.0)];
_nameLab.textAlignment = NSTextAlignmentCenter;
_nameLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHex(0xE8E9E9), DSWhite);
}
return _nameLab;
}
- (UIImageView *)volumeIcon {
if (!_volumeIcon) {
_volumeIcon = [[UIImageView alloc] dk_initWithImagePicker:DKImagePickerWithNames(@"noise_volume_icon", @"dk_noise_volume_icon", @"dk_noise_volume_icon")];
}
return _volumeIcon;
}
- (UISlider *)volumeSlider {
if (!_volumeSlider) {
_volumeSlider = [UISlider new];
[_volumeSlider cornerRadius:2.0];
_volumeSlider.minimumTrackTintColor = BrandColor;
_volumeSlider.dk_maximumTrackTintColorPicker = DKColorPickerWithColors(ColorFromHex(0xE3E1E1), ColorFromHex(0x131724), DSWhite);
[_volumeSlider setThumbImage:[UIImage imageNamed:@"muse_slider_thumbImage"] forState:UIControlStateNormal];
[_volumeSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[_volumeSlider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
[_volumeSlider addTarget:self action:@selector(sliderTouchUpInSide:) forControlEvents:UIControlEventTouchUpInside];
// 为UISlider添加点击事件
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTapGesture:)];
_tapGesture.delegate = self;
[_volumeSlider addGestureRecognizer:_tapGesture];
}
return _volumeSlider;
}
- (UIButton *)deleteBtn {
if (!_deleteBtn) {
_deleteBtn = [UIButton new];
[_deleteBtn dk_setImage:DKImagePickerWithNames(@"noise_delete_icon", @"dk_noise_delete_icon", @"noise_delete_icon") forState:UIControlStateNormal];
[_deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _deleteBtn;
}
@end
//
// NoisePlayView.h
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface NoisePlayView : UIView
- (void)show;
@end
NS_ASSUME_NONNULL_END
//
// NoisePlayView.m
// DreamSleep
//
// Created by peter on 2022/5/13.
//
#import "NoisePlayView.h"
#import "NoisePlayCell.h"
#import "NoiseAudioCell.h"
@interface NoisePlayView () <UITableViewDelegate, UITableViewDataSource, NoisePlayCellDelegate>
@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) NSArray *audioArr;
@property (nonatomic, strong) UITableView *playListView;
@property (nonatomic, strong) UIButton *oneClickBtn;
@end
@implementation NoisePlayView
- (instancetype)init {
if (self = [super initWithFrame:[UIScreen mainScreen].bounds]) {
self.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHexA(0x161E38, .6), ColorFromHexA(0x161E38, .6), DSWhite);
[self addSubview:self.headView];
[self addSubview:self.playListView];
[self addSubview:self.oneClickBtn];
[self.oneClickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.size.mas_equalTo(CGSizeMake(155, 40));
make.bottom.equalTo(self).offset(-Bottom_SafeArea_Height-50);
}];
}
return self;
}
- (void)show {
[DSKeyWindow addSubview:self];
NSArray *playList = [NoiseDataManager sharedNoiseDataManager].playList;
if (playList) {
self.audioArr = playList;
[self.playListView reloadData];
}
}
- (void)oneClickAction:(UIButton *)sender {
for (NoiseAudioCell *audioCell in self.audioArr) {
FSAudioStream *audioStream = audioCell.model.audioStream;
if (sender.selected) {
[audioStream pause];
} else {
[audioStream pause];
}
}
sender.selected = !sender.selected;
}
- (void)clearAllAction:(UIButton *)sender {
for (NoiseAudioCell *audioCell in self.audioArr) {
[audioCell.model.audioStream stop];
audioCell.audioIV.selected = NO;
}
self.audioArr = @[];
[NoiseDataManager sharedNoiseDataManager].playList = self.audioArr;
[self.playListView reloadData];
[self removeFromSuperview];
}
- (void)closeAction:(UIButton *)sender {
[self removeFromSuperview];
}
#pragma mark - UITableViewDelegate && UITableViewDataSource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.audioArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"NoisePlayCellID";
NoisePlayCell *cell = (NoisePlayCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[NoisePlayCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.delegate = self;
NoiseAudioCell *audioCell = self.audioArr[indexPath.row];
cell.model = audioCell.model;
cell.indexPath = indexPath;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 77;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 93 + Bottom_SafeArea_Height;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 93 + Bottom_SafeArea_Height)];
}
#pragma mark - NoisePlayCellDelegate
- (void)didRemoveItem:(NSIndexPath *)indexPath {
// 将要删除的音频停止播放并且设置为非选中状态
NoiseAudioCell *audioCell = self.audioArr[indexPath.row];
[audioCell.model.audioStream stop];
audioCell.audioIV.selected = NO;
// 删除数据源
NSMutableArray *tmpArr = [NSMutableArray arrayWithArray:self.audioArr];
[tmpArr removeObjectAtIndex:indexPath.row];
self.audioArr = [tmpArr copy];
[NoiseDataManager sharedNoiseDataManager].playList = self.audioArr;
// 执行删除动画
[self.playListView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
dispatch_after(.1, dispatch_get_main_queue(), ^{
[self.playListView reloadData];
});
if (self.audioArr.count == 0) { [self removeFromSuperview]; }
}
- (void)didSetVolume:(float)volume indexPath:(NSIndexPath *)indexPath {
NoiseAudioCell *audioCell = self.audioArr[indexPath.row];
[audioCell.model.audioStream setVolume:volume];
}
#pragma mark - lazy
- (UIView *)headView {
if (!_headView) {
_headView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, self.width, 60)];
_headView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
[_headView setCornerRadiusRect:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadius:24];
UIButton *clearAllBtn = [UIButton btnWithTitle:@"清除全部" titleColor:BrandColor font:SysFont(12.0)];
[clearAllBtn cornerRadius:12.0];
clearAllBtn.layer.borderColor = BrandColor.CGColor;
clearAllBtn.layer.borderWidth = 1.0;
[clearAllBtn addTarget:self action:@selector(clearAllAction:) forControlEvents:UIControlEventTouchUpInside];
[_headView addSubview:clearAllBtn];
UIButton *closeBtn = [UIButton new];
[closeBtn dk_setImage:DKImagePickerWithNames(@"home_close", @"dk_home_close", @"home_close") forState:UIControlStateNormal];
[closeBtn addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside];
[_headView addSubview:closeBtn];
[clearAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_headView).offset(15);
make.size.mas_equalTo(CGSizeMake(67, 26));
make.centerY.equalTo(_headView);
}];
[closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_headView).offset(-15);
make.size.mas_equalTo(CGSizeMake(30, 30));
make.centerY.equalTo(_headView);
}];
}
return _headView;
}
- (UITableView *)playListView {
if (!_playListView) {
CGFloat y = CGRectGetMaxY(self.headView.frame);
_playListView = [[UITableView alloc] initWithFrame:CGRectMake(0, y, self.width, self.height - y) style:UITableViewStyleGrouped];
_playListView.showsVerticalScrollIndicator = NO;
_playListView.bounces = NO;
_playListView.delegate = self;
_playListView.dataSource = self;
_playListView.dk_backgroundColorPicker = DKColorPickerWithKey(TabBarBG);
}
return _playListView;
}
- (UIButton *)oneClickBtn {
if (!_oneClickBtn) {
_oneClickBtn = [UIButton btnWithTitle:@"一键暂停" titleColor:DSWhite font:BoldFont(16) bgColor:BrandColor];
[_oneClickBtn addTarget:self action:@selector(oneClickAction:) forControlEvents:UIControlEventTouchUpInside];
[_oneClickBtn cornerRadius:22];
[_oneClickBtn setTitle:@"一键暂停" forState:UIControlStateNormal];
[_oneClickBtn setTitle:@"一键开启" forState:UIControlStateSelected];
}
return _oneClickBtn;
}
- (NSArray *)audioArr {
if (!_audioArr) {
_audioArr = [NSArray array];
}
return _audioArr;
}
@end
...@@ -154,31 +154,6 @@ static NSString *mainCell = @"inxx_mainCell"; ...@@ -154,31 +154,6 @@ static NSString *mainCell = @"inxx_mainCell";
[self updateCurrentScrollViewPageContentOffsetByIndex:self.selectedIndex]; [self updateCurrentScrollViewPageContentOffsetByIndex:self.selectedIndex];
//3. 更新collection main的显示index 位置 //3. 更新collection main的显示index 位置
[self.collectionMain scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO]; [self.collectionMain scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:self.selectedIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
// for (int i = 0; i < data.count; i++) {
// NoiseTypeModel *typeModel = data[i];
// if (i == 0) { typeModel.isSelected = YES; }
// }
// self.pageTypes = data;
// self.selectedIndex = 0;
//
// [self config];
//
// if (self.scrollViewPage) { [self.scrollViewPage removeFromSuperview]; }
// [self addScrollViewPage];
// [self addSubview:self.bodyPageView];
// [self.scrollViewPage mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.left.right.equalTo(self);
// make.height.equalTo(@40);
// }];
// [self.bodyPageView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.top.equalTo(self.scrollViewPage.mas_bottom);
// make.left.bottom.right.equalTo(self);
// }];
// [self addPageBottomLine];
// [self updateLineFrameWithIndex:self.selectedIndex];
//
// [self addObserver:self forKeyPath:@"selectedIndex" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
} }
- (void)configProperties { - (void)configProperties {
...@@ -279,7 +254,7 @@ CGRect childFrame; ...@@ -279,7 +254,7 @@ CGRect childFrame;
layout.minimumInteritemSpacing = 0; layout.minimumInteritemSpacing = 0;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
CGFloat y = _onNavigationBar ? 0 : _pageBarHeight; CGFloat y = _onNavigationBar ? 0 : _pageBarHeight;
layout.itemSize = CGSizeMake(_pageMenuW, 327); layout.itemSize = CGSizeMake(_pageMenuW, 327 + 70);
CGRect frame = CGRectMake(0, y, layout.itemSize.width, layout.itemSize.height); CGRect frame = CGRectMake(0, y, layout.itemSize.width, layout.itemSize.height);
PopEnabeldCollectionView *collection = [[PopEnabeldCollectionView alloc] initWithFrame:frame collectionViewLayout:layout]; PopEnabeldCollectionView *collection = [[PopEnabeldCollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
collection.backgroundColor = [UIColor whiteColor]; collection.backgroundColor = [UIColor whiteColor];
...@@ -609,7 +584,7 @@ static float oldOffsetX; ...@@ -609,7 +584,7 @@ static float oldOffsetX;
/// @param x SrollX /// @param x SrollX
- (void)changePageTitlePropertyiesWithSrollX:(CGFloat)x { - (void)changePageTitlePropertyiesWithSrollX:(CGFloat)x {
//创建通用变量 // 创建通用变量
int pageIndex = ABS(x) / kScreenWidth; int pageIndex = ABS(x) / kScreenWidth;
CGFloat xInScreen = x-kScreenWidth*pageIndex; //一屏内的位移距离 CGFloat xInScreen = x-kScreenWidth*pageIndex; //一屏内的位移距离
...@@ -650,23 +625,23 @@ static float oldOffsetX; ...@@ -650,23 +625,23 @@ static float oldOffsetX;
} }
if (_pageTitleColorChangeType == PageTitleColorChangeTypeScrolling) { // if (_pageTitleColorChangeType == PageTitleColorChangeTypeScrolling) {
NSArray *rgba0 = [self getRGBValueFromColor:_titleColor]; // NSArray *rgba0 = [self getRGBValueFromColor:_titleColor];
NSArray *rgba1 = [self getRGBValueFromColor:_titleSelectedColor]; // NSArray *rgba1 = [self getRGBValueFromColor:_titleSelectedColor];
CGFloat diffR = xInScreen / kScreenWidth * ([rgba1[0] floatValue] - [rgba0[0] floatValue]); // CGFloat diffR = xInScreen / kScreenWidth * ([rgba1[0] floatValue] - [rgba0[0] floatValue]);
CGFloat diffG = xInScreen / kScreenWidth * ([rgba1[1] floatValue] - [rgba0[1] floatValue]); // CGFloat diffG = xInScreen / kScreenWidth * ([rgba1[1] floatValue] - [rgba0[1] floatValue]);
CGFloat diffB = xInScreen / kScreenWidth * ([rgba1[2] floatValue] - [rgba0[2] floatValue]); // CGFloat diffB = xInScreen / kScreenWidth * ([rgba1[2] floatValue] - [rgba0[2] floatValue]);
CGFloat runingRed0 = [rgba0[0] floatValue] + diffR; // CGFloat runingRed0 = [rgba0[0] floatValue] + diffR;
CGFloat runingGreen0 = [rgba0[1] floatValue] + diffG; // CGFloat runingGreen0 = [rgba0[1] floatValue] + diffG;
CGFloat runingBlue0 = [rgba0[2] floatValue] + diffB; // CGFloat runingBlue0 = [rgba0[2] floatValue] + diffB;
CGFloat runingred1 = [rgba1[0] floatValue] - diffR; // CGFloat runingred1 = [rgba1[0] floatValue] - diffR;
CGFloat runinGreen1 = [rgba1[1] floatValue] - diffG; // CGFloat runinGreen1 = [rgba1[1] floatValue] - diffG;
CGFloat runingBlue1 = [rgba1[2] floatValue] - diffB; // CGFloat runingBlue1 = [rgba1[2] floatValue] - diffB;
UIColor *runtimeColor0 = [UIColor colorWithRed:runingRed0 green:runingGreen0 blue:runingBlue0 alpha:1.0]; // UIColor *runtimeColor0 = [UIColor colorWithRed:runingRed0 green:runingGreen0 blue:runingBlue0 alpha:1.0];
UIColor *runtimeColor1 = [UIColor colorWithRed:runingred1 green:runinGreen1 blue:runingBlue1 alpha:1.0]; // UIColor *runtimeColor1 = [UIColor colorWithRed:runingred1 green:runinGreen1 blue:runingBlue1 alpha:1.0];
oldCell.titleLabel.textColor = runtimeColor1; // oldCell.titleLabel.textColor = runtimeColor1;
newCell.titleLabel.textColor = runtimeColor0; // newCell.titleLabel.textColor = runtimeColor0;
} // }
} }
/** 系统API获取UIColor的RGBA值 */ /** 系统API获取UIColor的RGBA值 */
......
...@@ -9,5 +9,7 @@ ...@@ -9,5 +9,7 @@
@interface AppDelegate : UIResponder <UIApplicationDelegate> @interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow * window; @property (strong, nonatomic) UIWindow * window;
/// 选中的白噪音数据
@property (nonatomic, strong) NSArray *playList;
@end @end
{
"images" : [
{
"filename" : "dk_ noise_volume_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "dk_ noise_volume_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "dk_noise_delete_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "dk_noise_delete_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "dk_noise_delete_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "dk_noise_up.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "dk_noise_up@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "dk_noise_up@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "dk_noise_volume_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "noise_delete_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "noise_delete_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "noise_delete_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "noise_up.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "noise_up@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "noise_up@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "noise_volume_icon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "noise_volume_icon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "noise_volume_icon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!