Commit 6b150246 cgx

网络缺省页白天黑夜模式适配

1 个父辈 e932fb68
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
D0B5ECC827F2E97A003EDFE3 /* MacroFuncUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECC727F2E97A003EDFE3 /* MacroFuncUtil.m */; }; D0B5ECC827F2E97A003EDFE3 /* MacroFuncUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECC727F2E97A003EDFE3 /* MacroFuncUtil.m */; };
D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECD427F2F0B2003EDFE3 /* AdaptationUtil.m */; }; D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECD427F2F0B2003EDFE3 /* AdaptationUtil.m */; };
D0B5ECD827F2F1B0003EDFE3 /* ServerAPIUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECD727F2F1B0003EDFE3 /* ServerAPIUtil.m */; }; D0B5ECD827F2F1B0003EDFE3 /* ServerAPIUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECD727F2F1B0003EDFE3 /* ServerAPIUtil.m */; };
D0BB9AA4281626F200DB209E /* ExceptionDefaultView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */; };
D0BE32E62814D42B006539BE /* HomeRequestModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BE32E52814D42B006539BE /* HomeRequestModel.m */; }; D0BE32E62814D42B006539BE /* HomeRequestModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BE32E52814D42B006539BE /* HomeRequestModel.m */; };
D0BE32E9281551EB006539BE /* ShareAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BE32E8281551EB006539BE /* ShareAlertView.m */; }; D0BE32E9281551EB006539BE /* ShareAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BE32E8281551EB006539BE /* ShareAlertView.m */; };
D0C09ED728007D9100709D4C /* relax_normal_lottie.json in Resources */ = {isa = PBXBuildFile; fileRef = D0C09ED328007D9100709D4C /* relax_normal_lottie.json */; }; D0C09ED728007D9100709D4C /* relax_normal_lottie.json in Resources */ = {isa = PBXBuildFile; fileRef = D0C09ED328007D9100709D4C /* relax_normal_lottie.json */; };
...@@ -271,6 +272,8 @@ ...@@ -271,6 +272,8 @@
D0B5ECD427F2F0B2003EDFE3 /* AdaptationUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AdaptationUtil.m; sourceTree = "<group>"; }; D0B5ECD427F2F0B2003EDFE3 /* AdaptationUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AdaptationUtil.m; sourceTree = "<group>"; };
D0B5ECD627F2F1B0003EDFE3 /* ServerAPIUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ServerAPIUtil.h; sourceTree = "<group>"; }; D0B5ECD627F2F1B0003EDFE3 /* ServerAPIUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ServerAPIUtil.h; sourceTree = "<group>"; };
D0B5ECD727F2F1B0003EDFE3 /* ServerAPIUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ServerAPIUtil.m; sourceTree = "<group>"; }; D0B5ECD727F2F1B0003EDFE3 /* ServerAPIUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ServerAPIUtil.m; sourceTree = "<group>"; };
D0BB9AA2281626F200DB209E /* ExceptionDefaultView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExceptionDefaultView.h; sourceTree = "<group>"; };
D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExceptionDefaultView.m; sourceTree = "<group>"; };
D0BE32E42814D42B006539BE /* HomeRequestModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeRequestModel.h; sourceTree = "<group>"; }; D0BE32E42814D42B006539BE /* HomeRequestModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HomeRequestModel.h; sourceTree = "<group>"; };
D0BE32E52814D42B006539BE /* HomeRequestModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeRequestModel.m; sourceTree = "<group>"; }; D0BE32E52814D42B006539BE /* HomeRequestModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HomeRequestModel.m; sourceTree = "<group>"; };
D0BE32E7281551EB006539BE /* ShareAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareAlertView.h; sourceTree = "<group>"; }; D0BE32E7281551EB006539BE /* ShareAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareAlertView.h; sourceTree = "<group>"; };
...@@ -607,10 +610,12 @@ ...@@ -607,10 +610,12 @@
D07A657A2815897A00C15AF6 /* H5 */ = { D07A657A2815897A00C15AF6 /* H5 */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D07A657B28158A1900C15AF6 /* DsWebController.h */,
D07A657C28158A1900C15AF6 /* DsWebController.m */,
D07A65812815911D00C15AF6 /* DsMaskView.h */, D07A65812815911D00C15AF6 /* DsMaskView.h */,
D07A65822815911D00C15AF6 /* DsMaskView.m */, D07A65822815911D00C15AF6 /* DsMaskView.m */,
D0BB9AA2281626F200DB209E /* ExceptionDefaultView.h */,
D0BB9AA3281626F200DB209E /* ExceptionDefaultView.m */,
D07A657B28158A1900C15AF6 /* DsWebController.h */,
D07A657C28158A1900C15AF6 /* DsWebController.m */,
); );
path = H5; path = H5;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1036,6 +1041,7 @@ ...@@ -1036,6 +1041,7 @@
D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */, D09D0E9D280D73B6008DEDAB /* InviteController.m in Sources */,
D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */, D04B3D9A27F6D4D90022F8DF /* LeadingController.m in Sources */,
D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */, D053BEE9280F9E310028CCFC /* CloseAlertView.m in Sources */,
D0BB9AA4281626F200DB209E /* ExceptionDefaultView.m in Sources */,
D0B5ECD827F2F1B0003EDFE3 /* ServerAPIUtil.m in Sources */, D0B5ECD827F2F1B0003EDFE3 /* ServerAPIUtil.m in Sources */,
D0B5ECA627F2D9DE003EDFE3 /* AppDelegate.m in Sources */, D0B5ECA627F2D9DE003EDFE3 /* AppDelegate.m in Sources */,
D07DACA82810557D0067A1BF /* RSKImageCropViewController.m in Sources */, D07DACA82810557D0067A1BF /* RSKImageCropViewController.m in Sources */,
......
...@@ -8,12 +8,15 @@ ...@@ -8,12 +8,15 @@
#import "DsWebController.h" #import "DsWebController.h"
#import <WebKit/webKit.h> #import <WebKit/webKit.h>
#import "DsMaskView.h" #import "DsMaskView.h"
#import "ExceptionDefaultView.h"
@interface DsWebController () <WKNavigationDelegate> @interface DsWebController () <WKNavigationDelegate>
@property (nonatomic, copy) NSString *naviTitle; @property (nonatomic, copy) NSString *naviTitle;
@property (nonatomic, strong) NSURL *linkUrl; @property (nonatomic, strong) NSURL *linkUrl;
@property (nonatomic, strong) WKWebView *webView; @property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) NSMutableURLRequest *request;
@property (nonatomic, strong) UIProgressView *progressView; @property (nonatomic, strong) UIProgressView *progressView;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView;
@end @end
@implementation DsWebController @implementation DsWebController
...@@ -30,7 +33,7 @@ ...@@ -30,7 +33,7 @@
[super viewDidLoad]; [super viewDidLoad];
self.navigationItem.title = self.naviTitle; self.navigationItem.title = self.naviTitle;
self.view.backgroundColor = DSWhite; self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.webView]; [self.view addSubview:self.webView];
[self.view addSubview:self.progressView]; [self.view addSubview:self.progressView];
...@@ -41,8 +44,6 @@ ...@@ -41,8 +44,6 @@
[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) { [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view); make.top.left.right.equalTo(self.view);
}]; }];
[DsMaskView showMaskWithSuperView:self.view];
} }
- (void)dealloc { - (void)dealloc {
...@@ -60,23 +61,21 @@ ...@@ -60,23 +61,21 @@
} }
#pragma mark - WKNavigationDelegate #pragma mark - WKNavigationDelegate
// 开始加载 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation {
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
} }
// 加载成功
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
self.exceptionView.hidden = YES;
[DsMaskView showMaskWithSuperView:self.view];
self.webView.hidden = NO;
} }
// 加载失败
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error { - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
DSLog(@"加载失败:%@", error.userInfo); DSLog(@"加载失败:%@", error.userInfo);
self.exceptionView.hidden = NO;
// 显示加载失败状态视图
} }
#pragma mark - lazy #pragma mark - lazy
...@@ -84,12 +83,15 @@ ...@@ -84,12 +83,15 @@
if (!_webView) { if (!_webView) {
_webView = [[WKWebView alloc] init]; _webView = [[WKWebView alloc] init];
_webView.navigationDelegate = self; _webView.navigationDelegate = self;
_webView.backgroundColor = DSWhite; _webView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_webView.scrollView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_webView.scrollView.showsVerticalScrollIndicator = NO; _webView.scrollView.showsVerticalScrollIndicator = NO;
_webView.hidden = YES;
_webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil]; [_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:self.linkUrl]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:self.linkUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
[_webView loadRequest:request]; self.request = request;
[_webView loadRequest:self.request];
} }
return _webView; return _webView;
} }
...@@ -98,11 +100,24 @@ ...@@ -98,11 +100,24 @@
if (!_progressView) { if (!_progressView) {
_progressView = [[UIProgressView alloc] init]; _progressView = [[UIProgressView alloc] init];
_progressView.progressTintColor = HighlightColor; _progressView.progressTintColor = HighlightColor;
_progressView.trackTintColor = DSWhite; _progressView.dk_trackTintColorPicker = DKColorPickerWithKey(VCViewBG);
} }
return _progressView; return _progressView;
} }
- (ExceptionDefaultView *)exceptionView {
if (!_exceptionView) {
WS(weakSelf);
_exceptionView = [[ExceptionDefaultView alloc] initWithType:ExceptionTypeNet block:^{
weakSelf.progressView.hidden = NO;
weakSelf.progressView.progress = 0;
weakSelf.exceptionView.hidden = YES;
[weakSelf.webView loadRequest:self.request];
} superView:self.view];
}
return _exceptionView;
}
#pragma mark - H5页面导航栏为默认模式 #pragma mark - H5页面导航栏为默认模式
- (NaviStyle)navigationBarStyle { - (NaviStyle)navigationBarStyle {
return NaviStyleDefault; return NaviStyleDefault;
......
//
// ExceptionDefaultView.h
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
// 异常处理类型
typedef NS_ENUM(NSInteger, ExceptionType) {
ExceptionTypeNet
};
// 处理事件回调
typedef void (^DealBlock)(void);
/// 异常缺省页
@interface ExceptionDefaultView : UIView
- (instancetype)initWithType:(ExceptionType)type block:(DealBlock)block superView:(UIView *)superView;
@end
NS_ASSUME_NONNULL_END
//
// ExceptionDefaultView.m
// DreamSleep
//
// Created by peter on 2022/4/25.
//
#import "ExceptionDefaultView.h"
@interface ExceptionDefaultView ()
@property (nonatomic, strong) UIImageView *exceptionIV;
@property (nonatomic, strong) UILabel *exceptLab;
@property (nonatomic, strong) UIButton *dealBtn;
@property (nonatomic, copy) DealBlock dealBlock;
@property (nonatomic, assign) ExceptionType type;
@end
@implementation ExceptionDefaultView
- (instancetype)initWithType:(ExceptionType)type block:(DealBlock)block superView:(UIView *)superView {
if (self = [super initWithFrame:CGRectZero]) {
_dealBlock = block;
_type = type;
self.hidden = YES;
[superView addSubview:self];
[self addSubview:self.exceptionIV];
[self addSubview:self.exceptLab];
[self addSubview:self.dealBtn];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(superView);
make.center.equalTo(superView);
}];
[self.exceptionIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.top.equalTo(self);
}];
[self.exceptLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.left.equalTo(self).offset(5);
make.right.equalTo(self).offset(-5);
make.top.equalTo(self.exceptionIV.mas_bottom).offset(42);
}];
[self.dealBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.size.mas_equalTo(CGSizeMake(155, 40));
make.top.equalTo(self.exceptLab.mas_bottom).offset(42);
make.bottom.equalTo(self).offset(-30);
}];
}
return self;
}
- (void)dealloc {
DSLog(@"deallocdeallocdealloc");
}
#pragma mark - Actions
- (void)dealAction {
if (self.dealBlock) { self.dealBlock(); }
}
#pragma mark - lazy
- (UIImageView *)exceptionIV {
if (!_exceptionIV) {
_exceptionIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"netDefault"]];
}
return _exceptionIV;
}
- (UILabel *)exceptLab {
if (!_exceptLab) {
_exceptLab = [UILabel labWithText:[self getExceptionInfoWithType:self.type] font:SysFont(14) fit:YES];
_exceptLab.textAlignment = NSTextAlignmentCenter;
_exceptLab.dk_textColorPicker = DKColorPickerWithKey(SubTEXT);
}
return _exceptLab;
}
- (UIButton *)dealBtn {
if (!_dealBtn) {
_dealBtn = [UIButton btnWithTitle:[self getDealBtnTitleWithType:self.type] titleColor:DSWhite font:BoldFont(16) bgColor:BrandColor];
[_dealBtn addTarget:self action:@selector(dealAction) forControlEvents:UIControlEventTouchUpInside];
[_dealBtn cornerRadius:20];
}
return _dealBtn;
}
#pragma mark - private
- (NSString *)getExceptionInfoWithType:(ExceptionType)type {
NSString *info = @"";
if (type == ExceptionTypeNet) {
info = @"当前网络环境较差,点击刷新重新加载~";
}
return info;
}
- (NSString *)getDealBtnTitleWithType:(ExceptionType)type {
NSString *title = @"";
if (type == ExceptionTypeNet) {
title = @"刷新";
}
return title;
}
@end
...@@ -5,19 +5,6 @@ ...@@ -5,19 +5,6 @@
// Created by peter on 2022/4/13. // Created by peter on 2022/4/13.
// //
//typedef NS_ENUM(NSInteger, DSErrCode) {
// /** 网络故障 */
// DSErrCodeNetFail = -9,
// /** 业务逻辑成功 */
// DSErrCodeSuccess = -1,
// /** token验证失败 */
// DSErrCodeTokenFail = 401,
// /** 数据异常 */
// DSErrCodeDataWrong = -666,
// /** 异常数据错误,需要额外处理异常 */
// DSErrCodeNeedExtraDeal = 400022
//};
// 响应码 // 响应码
typedef NS_ENUM(NSInteger, DSResCode) { typedef NS_ENUM(NSInteger, DSResCode) {
/** 网络故障 */ /** 网络故障 */
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
self.backgroundColor = AlertDarkColor; self.backgroundColor = AlertDarkColor;
self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6]; self.backgroundColor = [self.backgroundColor colorWithAlphaComponent:0.6];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[self addGestureRecognizer:tapGR];
[self addSubview:self.shareView]; [self addSubview:self.shareView];
[self.shareView mas_makeConstraints:^(MASConstraintMaker *make) { [self.shareView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self); make.centerX.equalTo(self);
...@@ -82,6 +85,12 @@ ...@@ -82,6 +85,12 @@
} }
} }
- (void)tapAction:(UITapGestureRecognizer *)gesture {
if (!CGRectContainsPoint(self.shareView.frame, [gesture locationInView:self])) {
[self dismissShareAlertView];
}
}
#pragma mark - public #pragma mark - public
- (void)showShareAlertView { - (void)showShareAlertView {
[DSKeyWindow addSubview:self]; [DSKeyWindow addSubview:self];
......
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"filename" : "netDefault.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "netDefault@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "netDefault@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!