Commit 926ff181 cgx

优化我的主界面(自定义导航栏)

1 个父辈 374d592f
......@@ -62,6 +62,7 @@
D0506B1B2805500E00229278 /* SafeHelperCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */; };
D051032E282A4E9200560A0D /* instant_eternity.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = D051032C282A4E9200560A0D /* instant_eternity.mp3 */; };
D051032F282A4E9200560A0D /* fse.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = D051032D282A4E9200560A0D /* fse.mp3 */; };
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0534F082835D90400F8892E /* DSNaviBarViewController.m */; };
D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D053BEE8280F9E310028CCFC /* CloseAlertView.m */; };
D054CCB52830DE5600420DC4 /* NoisePlayerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = D054CCB42830DE5600420DC4 /* NoisePlayerManager.m */; };
D054CCB82830E3AC00420DC4 /* NoisePlayItem.m in Sources */ = {isa = PBXBuildFile; fileRef = D054CCB72830E3AC00420DC4 /* NoisePlayItem.m */; };
......@@ -304,6 +305,8 @@
D0506B1A2805500E00229278 /* SafeHelperCollectionViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SafeHelperCollectionViewCell.m; sourceTree = "<group>"; };
D051032C282A4E9200560A0D /* instant_eternity.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = instant_eternity.mp3; sourceTree = "<group>"; };
D051032D282A4E9200560A0D /* fse.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = fse.mp3; sourceTree = "<group>"; };
D0534F072835D90400F8892E /* DSNaviBarViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DSNaviBarViewController.h; sourceTree = "<group>"; };
D0534F082835D90400F8892E /* DSNaviBarViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DSNaviBarViewController.m; sourceTree = "<group>"; };
D053BEE7280F9E310028CCFC /* CloseAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CloseAlertView.h; sourceTree = "<group>"; };
D053BEE8280F9E310028CCFC /* CloseAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CloseAlertView.m; sourceTree = "<group>"; };
D054CCB32830DE5600420DC4 /* NoisePlayerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NoisePlayerManager.h; sourceTree = "<group>"; };
......@@ -1419,6 +1422,8 @@
D04B3DAA27F6EEB40022F8DF /* DSTabBarController.m */,
D055BEBD2825267C00BC11A4 /* DSBaseViewController.h */,
D055BEBE2825267C00BC11A4 /* DSBaseViewController.m */,
D0534F072835D90400F8892E /* DSNaviBarViewController.h */,
D0534F082835D90400F8892E /* DSNaviBarViewController.m */,
);
path = Root;
sourceTree = "<group>";
......@@ -1647,6 +1652,7 @@
buildActionMask = 2147483647;
files = (
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D0534F092835D90400F8892E /* DSNaviBarViewController.m in Sources */,
D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */,
D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */,
D0D00199282C9402004EAFA1 /* NoiseView.m in Sources */,
......
......@@ -61,21 +61,6 @@
}];
}
#pragma mark - 隐藏导航栏
- (BOOL)isShowNavigationBar {
return YES;
}
#pragma mark - 设置状态栏文字颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
}
#pragma mark - 关闭侧滑
- (BOOL)enableInteractivePopGestureRecognizer {
return NO;
}
#pragma mark - Actions
- (void)backAction {
[super backAction];
......@@ -184,6 +169,7 @@
self.dkBackBtn.hidden = NO;
}
self.dsNaviBar.alpha = offset/kTopHeight(0);
self.isNeedUpdateStatusBarStyle = offset > 1 ? YES : NO;
}
#pragma mark - lazy
......
......@@ -99,6 +99,7 @@
- (UIImageView *)bgIV {
if (!_bgIV) {
_bgIV = [UIImageView new];
_bgIV.contentMode = UIViewContentModeScaleAspectFill;
}
return _bgIV;
}
......
......@@ -5,11 +5,11 @@
// Created by peter on 2022/4/1.
//
#import <UIKit/UIKit.h>
#import "DSNaviBarViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface ProfileController : UIViewController
@interface ProfileController : DSNaviBarViewController
@end
......
......@@ -21,32 +21,12 @@
@implementation ProfileController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"我的";
self.naviTitle = @"我的";
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.bgIV];
[self.view addSubview:self.profileTableView];
}
#pragma mark - 隐藏导航栏
- (BOOL)isShowNavigationBar {
return YES;
}
#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle {
// 我的界面需要对用户是否打开自动切换进行处理
if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
return ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) ? NaviStyleDark : NaviStyleLight;
} else {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
}
}
#pragma mark - 设置状态栏文字颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
[super viewDidLoad];
}
#pragma mark - ProfileTableViewDelegate
......@@ -103,6 +83,14 @@
}
}
- (void)showNaviBar:(CGFloat)alpha {
self.naviBarAlpha = alpha;
}
- (void)isUpdateStatusStyle:(BOOL)isUpdate {
self.isNeedUpdateStatusBarStyle = isUpdate;
}
#pragma mark - Actions
- (void)modifyUserInfoAction {
// 账户与资料页面
......
......@@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
@protocol ProfileTableViewDelegate <NSObject>
- (void)didSelectedIndexPath:(NSIndexPath *)indexPath;
- (void)modifyUserInfoAction;
- (void)showNaviBar:(CGFloat)alpha;
- (void)isUpdateStatusStyle:(BOOL)isUpdate;
@end
/// 个人中心TableView
......
......@@ -200,12 +200,15 @@
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
// CGFloat offset = scrollView.contentOffset.y;
// if (offset >= 1) {
// [self.ds_viewController.navigationController setNavigationBarHidden:NO animated:NO];
// } else if (offset == 0) {
// [self.ds_viewController.navigationController setNavigationBarHidden:YES animated:NO];
// }
CGFloat offset = scrollView.contentOffset.y;
if (offset >= 0) {
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(showNaviBar:)]) {
[self.profileDelegate showNaviBar:offset/kTopHeight(0)];
}
}
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(isUpdateStatusStyle:)]) {
[self.profileDelegate isUpdateStatusStyle:(offset >= 2 ? YES : NO)];
}
}
#pragma mark - Action
......
......@@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong) UIButton *cusBackBtn;
/// 白天/夜间模式导航栏返回按钮
@property (nonatomic, strong) UIButton *dkBackBtn;
/// 是否需要更新状态栏风格
@property (nonatomic, assign) BOOL isNeedUpdateStatusBarStyle;
/// 返回事件,由子类去实现
- (void)backAction;
......
......@@ -22,6 +22,30 @@
}
- (void)setIsNeedUpdateStatusBarStyle:(BOOL)isNeedUpdateStatusBarStyle {
_isNeedUpdateStatusBarStyle = isNeedUpdateStatusBarStyle;
// 手动调用更新状态栏
[self setNeedsStatusBarAppearanceUpdate];
}
#pragma mark - 关闭侧滑
- (BOOL)enableInteractivePopGestureRecognizer {
return NO;
}
#pragma mark - 隐藏导航栏
- (BOOL)isShowNavigationBar {
return YES;
}
#pragma mark - 设置状态栏文字颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
if (self.isNeedUpdateStatusBarStyle) {
return UIStatusBarStyleLightContent;
}
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
}
#pragma mark - lazy
- (UIView *)dsNaviBar {
if (!_dsNaviBar) {
......
//
// DSNaviBarViewController.h
// DreamSleep
//
// Created by peter on 2022/5/19.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 自定义导航栏基类
@interface DSNaviBarViewController : UIViewController
/// 导航栏标题
@property (nonatomic, copy) NSString *naviTitle;
/// 导航栏透明度
@property (nonatomic, assign) CGFloat naviBarAlpha;
/// 是否需要更新状态栏风格
@property (nonatomic, assign) BOOL isNeedUpdateStatusBarStyle;
@end
NS_ASSUME_NONNULL_END
//
// DSNaviBarViewController.m
// DreamSleep
//
// Created by peter on 2022/5/19.
//
#import "DSNaviBarViewController.h"
@interface DSNaviBarViewController ()
/// 自定义导航栏
@property (nonatomic, strong) UIView *dsNaviBar;
/// 导航栏title
@property (nonatomic, strong) UILabel *titleLab;
@end
@implementation DSNaviBarViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.dsNaviBar];
}
- (void)setNaviTitle:(NSString *)naviTitle {
_naviTitle = naviTitle;
self.titleLab.text = _naviTitle;
}
- (void)setNaviBarAlpha:(CGFloat)naviBarAlpha {
_naviBarAlpha = naviBarAlpha;
self.dsNaviBar.alpha = _naviBarAlpha;
}
- (void)setIsNeedUpdateStatusBarStyle:(BOOL)isNeedUpdateStatusBarStyle {
_isNeedUpdateStatusBarStyle = isNeedUpdateStatusBarStyle;
// 手动调用更新状态栏
[self setNeedsStatusBarAppearanceUpdate];
}
#pragma mark - 隐藏系统导航栏
- (BOOL)isShowNavigationBar {
return YES;
}
#pragma mark - 设置状态栏文字颜色
- (UIStatusBarStyle)preferredStatusBarStyle {
if (self.isNeedUpdateStatusBarStyle) {
return UIStatusBarStyleLightContent;
}
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
}
//#pragma mark - 导航栏日间、黑夜模式
//- (NaviStyle)navigationBarStyle {
// // 我的界面需要对用户是否打开自动切换进行处理
// if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
// return ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) ? NaviStyleDark : NaviStyleLight;
// } else {
// return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
// }
//}
#pragma mark - lazy
- (UIView *)dsNaviBar {
if (!_dsNaviBar) {
_dsNaviBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kTopHeight(0))];
_dsNaviBar.alpha = 0;
_dsNaviBar.backgroundColor = BrandColor;
[_dsNaviBar addSubview:self.titleLab];
[_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.dsNaviBar);
make.bottom.equalTo(self.dsNaviBar).offset(-9);
}];
}
return _dsNaviBar;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel labWithTextColor:DSWhite font:BoldFont(18)];
_titleLab.textAlignment = NSTextAlignmentCenter;
}
return _titleLab;
}
@end
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!