Commit bf2800a13e345edba24bb7a222f493de8750ecfc

Authored by zhangxiaowen
1 parent 65c2f102

no message

CNLiveMineModule/Classes/Controller/CNLiveMineController.m
@@ -308,7 +308,7 @@ static const CGFloat timeValue = 1.5; @@ -308,7 +308,7 @@ static const CGFloat timeValue = 1.5;
308 } 308 }
309 else if(item == 6){ 309 else if(item == 6){
310 // 小家音响 310 // 小家音响
311 - 311 + NSLog(@"小家音响");
312 } 312 }
313 else if(item == 7){ 313 else if(item == 7){
314 // 我的礼盒 314 // 我的礼盒
@@ -317,7 +317,7 @@ static const CGFloat timeValue = 1.5; @@ -317,7 +317,7 @@ static const CGFloat timeValue = 1.5;
317 } 317 }
318 else if(item == 8){ 318 else if(item == 8){
319 // 路径工具 319 // 路径工具
320 - 320 + NSLog(@"路径工具");
321 } 321 }
322 322
323 } 323 }
@@ -331,11 +331,11 @@ static const CGFloat timeValue = 1.5; @@ -331,11 +331,11 @@ static const CGFloat timeValue = 1.5;
331 { 331 {
332 if(item == 0){ 332 if(item == 0){
333 // 我的活动 333 // 我的活动
334 - 334 + NSLog(@"我的活动");
335 } 335 }
336 else if(item == 1){ 336 else if(item == 1){
337 // 我的记录 337 // 我的记录
338 - 338 + NSLog(@"我的记录");
339 } 339 }
340 } 340 }
341 break; 341 break;
CNLiveMineModule/Classes/Model/CNLiveMineRequest.m
@@ -32,5 +32,4 @@ @@ -32,5 +32,4 @@
32 }]; 32 }];
33 } 33 }
34 34
35 -  
36 @end 35 @end
Example/CNLiveMineModule.xcodeproj/project.pbxproj
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 8
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 084AE78223891906005C9A94 /* UIViewController+Present.m in Sources */ = {isa = PBXBuildFile; fileRef = 084AE78123891906005C9A94 /* UIViewController+Present.m */; }; 10 084AE78223891906005C9A94 /* UIViewController+Present.m in Sources */ = {isa = PBXBuildFile; fileRef = 084AE78123891906005C9A94 /* UIViewController+Present.m */; };
  11 + 08755590239B839E0025B3AE /* CNLiveWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0875558F239B839E0025B3AE /* CNLiveWebViewController.m */; };
11 08B0B213237D1A4D00337DEC /* CNLiveConfigurationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B211237D1A4D00337DEC /* CNLiveConfigurationManager.m */; }; 12 08B0B213237D1A4D00337DEC /* CNLiveConfigurationManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B211237D1A4D00337DEC /* CNLiveConfigurationManager.m */; };
12 08B0B216237D1DE400337DEC /* CNLivePageJumpManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B215237D1DE400337DEC /* CNLivePageJumpManager.m */; }; 13 08B0B216237D1DE400337DEC /* CNLivePageJumpManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B215237D1DE400337DEC /* CNLivePageJumpManager.m */; };
13 08B0B219237D1FAF00337DEC /* CNLiveRootControllerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B218237D1FAE00337DEC /* CNLiveRootControllerManager.m */; }; 14 08B0B219237D1FAF00337DEC /* CNLiveRootControllerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 08B0B218237D1FAE00337DEC /* CNLiveRootControllerManager.m */; };
@@ -44,6 +45,8 @@ @@ -44,6 +45,8 @@
44 /* Begin PBXFileReference section */ 45 /* Begin PBXFileReference section */
45 084AE78023891906005C9A94 /* UIViewController+Present.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Present.h"; sourceTree = "<group>"; }; 46 084AE78023891906005C9A94 /* UIViewController+Present.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Present.h"; sourceTree = "<group>"; };
46 084AE78123891906005C9A94 /* UIViewController+Present.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Present.m"; sourceTree = "<group>"; }; 47 084AE78123891906005C9A94 /* UIViewController+Present.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+Present.m"; sourceTree = "<group>"; };
  48 + 0875558E239B839E0025B3AE /* CNLiveWebViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CNLiveWebViewController.h; sourceTree = "<group>"; };
  49 + 0875558F239B839E0025B3AE /* CNLiveWebViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CNLiveWebViewController.m; sourceTree = "<group>"; };
47 08B0B20E237D1A4D00337DEC /* CNLiveConfigurationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLiveConfigurationManager.h; sourceTree = "<group>"; }; 50 08B0B20E237D1A4D00337DEC /* CNLiveConfigurationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLiveConfigurationManager.h; sourceTree = "<group>"; };
48 08B0B211237D1A4D00337DEC /* CNLiveConfigurationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveConfigurationManager.m; sourceTree = "<group>"; }; 51 08B0B211237D1A4D00337DEC /* CNLiveConfigurationManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CNLiveConfigurationManager.m; sourceTree = "<group>"; };
49 08B0B214237D1DE400337DEC /* CNLivePageJumpManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLivePageJumpManager.h; sourceTree = "<group>"; }; 52 08B0B214237D1DE400337DEC /* CNLivePageJumpManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CNLivePageJumpManager.h; sourceTree = "<group>"; };
@@ -167,6 +170,8 @@ @@ -167,6 +170,8 @@
167 6003F594195388D20070C39A /* Supporting Files */, 170 6003F594195388D20070C39A /* Supporting Files */,
168 084AE78023891906005C9A94 /* UIViewController+Present.h */, 171 084AE78023891906005C9A94 /* UIViewController+Present.h */,
169 084AE78123891906005C9A94 /* UIViewController+Present.m */, 172 084AE78123891906005C9A94 /* UIViewController+Present.m */,
  173 + 0875558E239B839E0025B3AE /* CNLiveWebViewController.h */,
  174 + 0875558F239B839E0025B3AE /* CNLiveWebViewController.m */,
170 ); 175 );
171 name = "Example for CNLiveMineModule"; 176 name = "Example for CNLiveMineModule";
172 path = CNLiveMineModule; 177 path = CNLiveMineModule;
@@ -514,6 +519,7 @@ @@ -514,6 +519,7 @@
514 6003F5A7195388D20070C39A /* CNLIVEViewController.m in Sources */, 519 6003F5A7195388D20070C39A /* CNLIVEViewController.m in Sources */,
515 08B0B21C237D227700337DEC /* CNLiveNotificationManager.m in Sources */, 520 08B0B21C237D227700337DEC /* CNLiveNotificationManager.m in Sources */,
516 6003F59A195388D20070C39A /* main.m in Sources */, 521 6003F59A195388D20070C39A /* main.m in Sources */,
  522 + 08755590239B839E0025B3AE /* CNLiveWebViewController.m in Sources */,
517 08B0B219237D1FAF00337DEC /* CNLiveRootControllerManager.m in Sources */, 523 08B0B219237D1FAF00337DEC /* CNLiveRootControllerManager.m in Sources */,
518 ); 524 );
519 runOnlyForDeploymentPostprocessing = 0; 525 runOnlyForDeploymentPostprocessing = 0;
Example/CNLiveMineModule/CNLiveWebViewController.h 0 → 100644
  1 +//
  2 +// CNLiveWebViewController.h
  3 +// CNLiveMineModule_Example
  4 +//
  5 +// Created by CNLive-zxw on 2019/12/7.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +NS_ASSUME_NONNULL_BEGIN
  12 +
  13 +@interface CNLiveWebViewController : UIViewController
  14 +- (instancetype)initWithUrl:(NSString *)url title:(nullable NSString *)title;
  15 +
  16 +- (instancetype)initWithUrl:(NSString *)url title:(nullable NSString *)title isShow:(BOOL)isShow;
  17 +
  18 +@end
  19 +
  20 +NS_ASSUME_NONNULL_END
Example/CNLiveMineModule/CNLiveWebViewController.m 0 → 100644
  1 +//
  2 +// CNLiveWebViewController.m
  3 +// CNLiveMineModule_Example
  4 +//
  5 +// Created by CNLive-zxw on 2019/12/7.
  6 +// Copyright © 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveWebViewController.h"
  10 +#import <WebKit/WebKit.h>
  11 +#import "CNLiveCategory.h"
  12 +
  13 +@interface CNLiveWebViewController ()<WKUIDelegate, WKNavigationDelegate>
  14 +@property (nonatomic, copy) NSString *url;
  15 +@property (nonatomic, assign) BOOL isShow;
  16 +
  17 +@property (nonatomic, strong) UIView *navigationBar;
  18 +@property (nonatomic, strong) WKWebView *webView;
  19 +@property (nonatomic, strong) UIProgressView *processView;
  20 +@property (nonatomic, weak) UILabel *titleLabel;
  21 +
  22 +@end
  23 +
  24 +@implementation CNLiveWebViewController
  25 +static const NSInteger margin = 10;
  26 +
  27 +#pragma mark - 初始化方法
  28 +- (instancetype)initWithUrl:(NSString *)url title:(nullable NSString *)title{
  29 + return [self initWithUrl:url title:title isShow:NO];
  30 +}
  31 +
  32 +- (instancetype)initWithUrl:(NSString *)url title:(nullable NSString *)title isShow:(BOOL)isShow {
  33 + self = [super init];
  34 + if (self) {
  35 + self.url = url;
  36 + self.title = title;
  37 + self.isShow = isShow;
  38 + }
  39 + return self;
  40 +}
  41 +- (void)setTitle:(NSString *)title{
  42 + _titleLabel.text = title;
  43 +}
  44 +
  45 +#pragma mark - 加载数据
  46 +- (void)loadUrl {
  47 + NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.url] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0];
  48 + [self.webView loadRequest:theRequest];
  49 +}
  50 +
  51 +#pragma mark - 生命周期
  52 +- (void)viewWillAppear:(BOOL)animated {
  53 + [super viewWillAppear:animated];
  54 + self.navigationController.navigationBarHidden = YES;
  55 +}
  56 +
  57 +- (void)viewWillDisappear:(BOOL)animated {
  58 + [super viewWillDisappear:animated];
  59 + self.navigationController.navigationBarHidden = NO;
  60 +}
  61 +
  62 +- (void)viewDidLoad {
  63 + [super viewDidLoad];
  64 + self.view.backgroundColor = [UIColor whiteColor];
  65 + if (@available(iOS 11, *)) {
  66 + self.webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  67 + }
  68 + else {
  69 + self.automaticallyAdjustsScrollViewInsets = NO;
  70 + }
  71 + [self createSubViews];
  72 + [self loadUrl];
  73 +}
  74 +
  75 +- (void)dealloc {
  76 + [self.webView stopLoading];
  77 + [self.webView removeObserver:self forKeyPath:@"estimatedProgress"];
  78 + if (!self.title) {
  79 + [self.webView removeObserver:self forKeyPath:@"title"];
  80 + }
  81 + self.webView.UIDelegate = nil;
  82 + self.webView.navigationDelegate = nil;
  83 + self.webView = nil;
  84 +
  85 +}
  86 +
  87 +- (void)createSubViews {
  88 + [self.view addSubview:self.navigationBar];
  89 + [self.view addSubview:self.webView];
  90 + [self.view addSubview:self.processView];
  91 +
  92 + [self.webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
  93 + if (!self.title) {
  94 + [self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
  95 + }
  96 +
  97 +}
  98 +
  99 +
  100 +#pragma mark - WKNavigationDelegate
  101 +// 在发送请求之前,决定是否跳转
  102 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler{
  103 + //允许跳转
  104 + decisionHandler(WKNavigationActionPolicyAllow);
  105 +
  106 +}
  107 +
  108 +// 页面开始加载时调用
  109 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
  110 +
  111 +}
  112 +
  113 +// 在收到响应后,决定是否跳转
  114 +- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{
  115 + //允许跳转
  116 + decisionHandler(WKNavigationResponsePolicyAllow);
  117 + //不允许跳转
  118 + //decisionHandler(WKNavigationResponsePolicyCancel);
  119 +}
  120 +
  121 +// 当内容开始返回时调用
  122 +- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
  123 +
  124 +}
  125 +
  126 +// 页面加载完成之后调用
  127 +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
  128 +
  129 +}
  130 +
  131 +// 页面加载失败时调用
  132 +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(nonnull NSError *)error{
  133 + NSLog(@"打印这个error%@",error);
  134 +
  135 +}
  136 +
  137 +// 接收到服务器跳转请求之后调用(重定向)
  138 +- (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation{
  139 +
  140 +}
  141 +
  142 +#pragma mark - 响应方法
  143 +//回退goBack
  144 +- (void)goBack {
  145 + if ([self.webView canGoBack]) {
  146 + [self.webView goBack];
  147 + }
  148 + else {
  149 + [self closeClick];
  150 + }
  151 +}
  152 +
  153 +//关闭pop
  154 +- (void)closeClick {
  155 + if (self.presentingViewController != nil) {
  156 + [self dismissViewControllerAnimated:YES completion:nil];
  157 +
  158 + }
  159 + else {
  160 + [self.navigationController popViewControllerAnimated:YES];
  161 + }
  162 +}
  163 +
  164 +/*
  165 +#pragma mark - Navigation
  166 +
  167 +// In a storyboard-based application, you will often want to do a little preparation before navigation
  168 +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  169 + // Get the new view controller using [segue destinationViewController].
  170 + // Pass the selected object to the new view controller.
  171 +}
  172 +*/
  173 +#pragma mark - KVO
  174 +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  175 + if ([keyPath isEqualToString:@"estimatedProgress"]) {
  176 + if (object == self.webView) {
  177 + [self.processView setAlpha:1.0f];
  178 + [self.processView setProgress:self.webView.estimatedProgress animated:YES];
  179 +
  180 + if(self.webView.estimatedProgress >= 1.0f) {
  181 +
  182 + [UIView animateWithDuration:0.3 delay:0.5 options:UIViewAnimationOptionCurveEaseOut animations:^{
  183 + [self.processView setAlpha:0.0f];
  184 +
  185 + } completion:^(BOOL finished) {
  186 + [self.processView setProgress:0.0f animated:NO];
  187 +
  188 + }];
  189 +
  190 + }
  191 +
  192 + }
  193 + else {
  194 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  195 + }
  196 +
  197 + }
  198 + else if ([keyPath isEqualToString:@"title"]){
  199 + if (object == self.webView) {
  200 + if (self.webView.title.length != 0) {
  201 + self.title = self.webView.title;
  202 +
  203 + }
  204 + }
  205 + else {
  206 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  207 + }
  208 + }
  209 + else {
  210 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  211 +
  212 + }
  213 +}
  214 +#pragma mark - 懒加载
  215 +- (UIView *)navigationBar{
  216 + if(!_navigationBar){
  217 + _navigationBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44+[UIApplication sharedApplication].statusBarFrame.size.height)];
  218 + _navigationBar.backgroundColor = [UIColor clearColor];
  219 + [self.view bringSubviewToFront:_navigationBar];
  220 +
  221 + UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  222 + leftBtn.adjustsImageWhenHighlighted = NO;
  223 + leftBtn.frame = CGRectMake(margin, [UIApplication sharedApplication].statusBarFrame.size.height, 44, 44);
  224 + UIImage *leftImage = [self getImageWithImageName:@"web_black_back" bundleName:@"CNLiveUserAgreementManager" targetClass:[self class]];
  225 + [leftBtn setImage:[leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  226 + [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  227 + [leftBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  228 + [_navigationBar addSubview:leftBtn];
  229 +
  230 + UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  231 + closeBtn.adjustsImageWhenHighlighted = NO;
  232 + closeBtn.frame = CGRectMake(44+margin, [UIApplication sharedApplication].statusBarFrame.size.height, 44, 44);
  233 + UIImage *closeImage = [self getImageWithImageName:@"web_black_close" bundleName:@"CNLiveUserAgreementManager" targetClass:[self class]];
  234 + [closeBtn setImage:[closeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  235 + [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
  236 + [closeBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
  237 + closeBtn.hidden = !self.isShow;
  238 + [_navigationBar addSubview:closeBtn];
  239 +
  240 + UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([[UIScreen mainScreen] bounds].size.width - 200)/2.0, [UIApplication sharedApplication].statusBarFrame.size.height, 200, 44)];
  241 + titleLabel.font = [UIFont boldSystemFontOfSize:17];
  242 + titleLabel.textColor = [UIColor blackColor];
  243 + titleLabel.text = self.title;
  244 + titleLabel.textAlignment = NSTextAlignmentCenter;
  245 + [_navigationBar addSubview:titleLabel];
  246 + _titleLabel = titleLabel;
  247 +
  248 + }
  249 + return _navigationBar;
  250 +}
  251 +
  252 +- (WKWebView *)webView{
  253 + if(!_webView){
  254 + WKWebViewConfiguration * configuration = [[WKWebViewConfiguration alloc] init];
  255 + configuration.allowsInlineMediaPlayback = YES;
  256 + WKPreferences *preferences = [WKPreferences new];
  257 + preferences.javaScriptCanOpenWindowsAutomatically = YES;
  258 + configuration.preferences = preferences;
  259 + _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height+44, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-([UIApplication sharedApplication].statusBarFrame.size.height+44)) configuration:configuration];
  260 + _webView.UIDelegate = self;
  261 + _webView.navigationDelegate = self;
  262 + _webView.contentMode = UIViewContentModeScaleAspectFit;
  263 + _webView.scrollView.showsHorizontalScrollIndicator = NO;
  264 + _webView.scrollView.showsVerticalScrollIndicator = NO;
  265 + _webView.allowsBackForwardNavigationGestures = YES;
  266 + _webView.allowsLinkPreview = NO;
  267 +
  268 + }
  269 + return _webView;
  270 +}
  271 +
  272 +- (UIProgressView *)processView{
  273 + if(!_processView){
  274 + _processView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, ([UIApplication sharedApplication].statusBarFrame.size.height+44)+0.5, [[UIScreen mainScreen] bounds].size.width, 1)];
  275 + _processView.progressTintColor = [UIColor colorWithRed:19/255.0 green:204/255.0 blue:12/255.0 alpha:1.0];
  276 + _processView.trackTintColor = [UIColor whiteColor];
  277 + }
  278 + return _processView;
  279 +}
  280 +
  281 +@end