Commit e932fb68 cgx

封装H5链接加载页面

1 个父辈 4e6dc930
......@@ -50,6 +50,8 @@
D07A4B27280E9BAA00BA0EC0 /* AccountController.m in Sources */ = {isa = PBXBuildFile; fileRef = D07A4B26280E9BAA00BA0EC0 /* AccountController.m */; };
D07A4B2A280EA6B600BA0EC0 /* UserInfoTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = D07A4B29280EA6B600BA0EC0 /* UserInfoTableView.m */; };
D07A4B2D280EA73B00BA0EC0 /* UserInfoView.m in Sources */ = {isa = PBXBuildFile; fileRef = D07A4B2C280EA73B00BA0EC0 /* UserInfoView.m */; };
D07A657D28158A1900C15AF6 /* DsWebController.m in Sources */ = {isa = PBXBuildFile; fileRef = D07A657C28158A1900C15AF6 /* DsWebController.m */; };
D07A65832815911D00C15AF6 /* DsMaskView.m in Sources */ = {isa = PBXBuildFile; fileRef = D07A65822815911D00C15AF6 /* DsMaskView.m */; };
D07DAC8D281048050067A1BF /* PhotoAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D07DAC8C281048050067A1BF /* PhotoAlertView.m */; };
D07DAC902810546A0067A1BF /* DSImagePickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = D07DAC8F2810546A0067A1BF /* DSImagePickerController.m */; };
D07DACA42810557D0067A1BF /* CGGeometry+RSKImageCropper.m in Sources */ = {isa = PBXBuildFile; fileRef = D07DAC922810557D0067A1BF /* CGGeometry+RSKImageCropper.m */; };
......@@ -193,6 +195,10 @@
D07A4B29280EA6B600BA0EC0 /* UserInfoTableView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserInfoTableView.m; sourceTree = "<group>"; };
D07A4B2B280EA73B00BA0EC0 /* UserInfoView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserInfoView.h; sourceTree = "<group>"; };
D07A4B2C280EA73B00BA0EC0 /* UserInfoView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UserInfoView.m; sourceTree = "<group>"; };
D07A657B28158A1900C15AF6 /* DsWebController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DsWebController.h; sourceTree = "<group>"; };
D07A657C28158A1900C15AF6 /* DsWebController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DsWebController.m; sourceTree = "<group>"; };
D07A65812815911D00C15AF6 /* DsMaskView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DsMaskView.h; sourceTree = "<group>"; };
D07A65822815911D00C15AF6 /* DsMaskView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DsMaskView.m; sourceTree = "<group>"; };
D07DAC8B281048050067A1BF /* PhotoAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotoAlertView.h; sourceTree = "<group>"; };
D07DAC8C281048050067A1BF /* PhotoAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotoAlertView.m; sourceTree = "<group>"; };
D07DAC8E2810546A0067A1BF /* DSImagePickerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DSImagePickerController.h; sourceTree = "<group>"; };
......@@ -598,6 +604,17 @@
path = Account;
sourceTree = "<group>";
};
D07A657A2815897A00C15AF6 /* H5 */ = {
isa = PBXGroup;
children = (
D07A657B28158A1900C15AF6 /* DsWebController.h */,
D07A657C28158A1900C15AF6 /* DsWebController.m */,
D07A65812815911D00C15AF6 /* DsMaskView.h */,
D07A65822815911D00C15AF6 /* DsMaskView.m */,
);
path = H5;
sourceTree = "<group>";
};
D07DAC912810557D0067A1BF /* RSKImageCropper */ = {
isa = PBXGroup;
children = (
......@@ -678,6 +695,7 @@
children = (
D091BBB82809024100487A50 /* DreamSleepBeta.entitlements */,
D0DF90AB28142F1300FC0F64 /* DreamSleepDebug.entitlements */,
D07A657A2815897A00C15AF6 /* H5 */,
D04567AA27F6D067009F0A82 /* Main */,
D04567AB27F6D0A5009F0A82 /* HomeModule */,
D04567AC27F6D0BA009F0A82 /* AISleepCoach */,
......@@ -1042,6 +1060,7 @@
D0E6600828080F97006562F2 /* SystemSetController.m in Sources */,
D091BBB72808F9DA00487A50 /* BreathTextView.m in Sources */,
D04B3DBB27F6F7940022F8DF /* AISleepCoachController.m in Sources */,
D07A65832815911D00C15AF6 /* DsMaskView.m in Sources */,
D0BE32E62814D42B006539BE /* HomeRequestModel.m in Sources */,
D0D3826728124E8A005BB219 /* FeedbackController.m in Sources */,
D027EE2627FB3DC0004BBA61 /* NetLoadingStateView.m in Sources */,
......@@ -1084,6 +1103,7 @@
D07A4B2A280EA6B600BA0EC0 /* UserInfoTableView.m in Sources */,
D0930F122801124E006B497A /* BaseNaviController.m in Sources */,
D0878F4F280C087E005F1B7F /* LoginController.m in Sources */,
D07A657D28158A1900C15AF6 /* DsWebController.m in Sources */,
D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */,
D0F808FE280421C20097899F /* ThreeMinuteController.m in Sources */,
D07A4B27280E9BAA00BA0EC0 /* AccountController.m in Sources */,
......
//
// DsMaskView.h
// DreamSleep
//
// Created by peter on 2022/4/24.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 自定义遮罩视图
@interface DsMaskView : UIView
/// 显示遮罩
/// @param superView superView
+ (void)showMaskWithSuperView:(UIView *)superView;
@end
NS_ASSUME_NONNULL_END
//
// DsMaskView.m
// DreamSleep
//
// Created by peter on 2022/4/24.
//
#import "DsMaskView.h"
@implementation DsMaskView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = ColorFromHex(0x6B7485);
self.alpha = .5;
self.userInteractionEnabled = NO;
self.hidden = ![self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight];
}
return self;
}
+ (void)showMaskWithSuperView:(UIView *)superView {
DsMaskView *maskView = [[DsMaskView alloc] init];
UIView *view = superView ? superView : DSKeyWindow;
[view addSubview:maskView];
[maskView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
}
@end
//
// DsWebController.h
// DreamSleep
//
// Created by peter on 2022/4/24.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 加载H5页面控制器
@interface DsWebController : UIViewController
/// 初始化方法
/// @param title 导航栏标题
/// @param link 传入h5链接
- (instancetype)initWithTitle:(NSString *)title link:(NSString *)link;
@end
NS_ASSUME_NONNULL_END
//
// DsWebController.m
// DreamSleep
//
// Created by peter on 2022/4/24.
//
#import "DsWebController.h"
#import <WebKit/webKit.h>
#import "DsMaskView.h"
@interface DsWebController () <WKNavigationDelegate>
@property (nonatomic, copy) NSString *naviTitle;
@property (nonatomic, strong) NSURL *linkUrl;
@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) UIProgressView *progressView;
@end
@implementation DsWebController
- (instancetype)initWithTitle:(NSString *)title link:(NSString *)link {
if (self = [super init]) {
self.naviTitle = title;
self.linkUrl = [NSURL URLWithString:link];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = self.naviTitle;
self.view.backgroundColor = DSWhite;
[self.view addSubview:self.webView];
[self.view addSubview:self.progressView];
[self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
}];
[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
}];
[DsMaskView showMaskWithSuperView:self.view];
}
- (void)dealloc {
[self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
}
#pragma mark - WKWebView的监听方法
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"estimatedProgress"]) {
[self.progressView setProgress:self.webView.estimatedProgress animated:YES];
self.progressView.hidden = self.progressView.progress == 1;
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
#pragma mark - WKNavigationDelegate
// 开始加载
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
// 加载成功
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
// 加载失败
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
DSLog(@"加载失败:%@", error.userInfo);
// 显示加载失败状态视图
}
#pragma mark - lazy
- (WKWebView *)webView {
if (!_webView) {
_webView = [[WKWebView alloc] init];
_webView.navigationDelegate = self;
_webView.backgroundColor = DSWhite;
_webView.scrollView.showsVerticalScrollIndicator = NO;
_webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
NSURLRequest *request = [NSURLRequest requestWithURL:self.linkUrl];
[_webView loadRequest:request];
}
return _webView;
}
- (UIProgressView *)progressView {
if (!_progressView) {
_progressView = [[UIProgressView alloc] init];
_progressView.progressTintColor = HighlightColor;
_progressView.trackTintColor = DSWhite;
}
return _progressView;
}
#pragma mark - H5页面导航栏为默认模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end
......@@ -82,7 +82,7 @@
BannerModel *model = self.bannerDatas[index];
switch (model.banner_id) {
case 13: { // 进入失眠拯救计划页面
[self.ds_viewController.navigationController pushViewController:[[PrivacyViewController alloc] initWithTitle:@"失眠拯救计划" link:[NSURL URLWithString:model.info_url] isDetail:YES] animated:YES];
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithTitle:@"失眠拯救计划" link:model.info_url] animated:YES];
}
break;
case 11: { // 切换到AI睡眠教练标签
......
......@@ -13,7 +13,7 @@
@property (nonatomic, strong) PrivacyView *policyView;
@property (nonatomic, strong) UIView *maskView;
@property (nonatomic, copy) NSString *naviTitle;
@property (nonatomic, copy) NSURL *link;
@property (nonatomic, strong) NSURL *link;
@property (nonatomic, assign) BOOL isDetail;
@property (nonatomic, strong) WKWebView *webView;
// 黑夜模式遮罩(到时候提取出来,全局通用)
......
......@@ -30,6 +30,7 @@
#import "NaviBarHandlerProtocol.h"
#import "BaseNaviController.h"
#import "DsWebController.h"
#import "DSProgressHUD.h"
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!