Commit b7a716a01a3369edcfa6a9b198a1c2ab37c2cc6c

Authored by 张旭
1 parent 8b97830d

添加webViewVC , 增加判断当前是哪页 显示隐藏tabbar

metaCode.xcodeproj/project.pbxproj
... ... @@ -8,6 +8,7 @@
8 8  
9 9 /* Begin PBXBuildFile section */
10 10 0D39E93D7229931C86EB1161 /* Pods_metaCode_metaCodeUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63D879B49B1E42F1584DD75E /* Pods_metaCode_metaCodeUITests.framework */; };
  11 + 19123FC12ABC11170075C883 /* CNWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19123FC02ABC11170075C883 /* CNWebViewController.swift */; };
11 12 19F1C2332AB5728B0083D06C /* CNIDCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F1C2322AB5728B0083D06C /* CNIDCardView.swift */; };
12 13 1DD2808DF02C120276F99F4D /* Pods_metaCode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F1C55A719CFEE073C06D37CE /* Pods_metaCode.framework */; };
13 14 7905BB492AB0588B0089BC50 /* CNLiveMineAuthResultViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7905BB482AB0588B0089BC50 /* CNLiveMineAuthResultViewController.swift */; };
... ... @@ -114,6 +115,7 @@
114 115 /* Begin PBXFileReference section */
115 116 0EC910AB9EBD717B04432BC4 /* Pods-metaCode-metaCodeUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode-metaCodeUITests.debug.xcconfig"; path = "Target Support Files/Pods-metaCode-metaCodeUITests/Pods-metaCode-metaCodeUITests.debug.xcconfig"; sourceTree = "<group>"; };
116 117 170BC5D0622EA2969D110A3B /* Pods-metaCode.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-metaCode.release.xcconfig"; path = "Target Support Files/Pods-metaCode/Pods-metaCode.release.xcconfig"; sourceTree = "<group>"; };
  118 + 19123FC02ABC11170075C883 /* CNWebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNWebViewController.swift; sourceTree = "<group>"; };
117 119 19F1C2322AB5728B0083D06C /* CNIDCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CNIDCardView.swift; sourceTree = "<group>"; };
118 120 54E09C540E13D78166D71395 /* Pods_metaCodeTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_metaCodeTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
119 121 63D879B49B1E42F1584DD75E /* Pods_metaCode_metaCodeUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_metaCode_metaCodeUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
... ... @@ -561,6 +563,7 @@
561 563 isa = PBXGroup;
562 564 children = (
563 565 7CD6754E2A2840B9008354C1 /* CNMetaCodeHomePageController.swift */,
  566 + 19123FC02ABC11170075C883 /* CNWebViewController.swift */,
564 567 );
565 568 name = Controller;
566 569 path = HomePage/Controller;
... ... @@ -891,6 +894,7 @@
891 894 790B1FB62A41938F0074CF00 /* UIImage+CNLiveExtensions.swift in Sources */,
892 895 790D019D2A2DCBD000C5978D /* UIView+CNLiveExtensions.swift in Sources */,
893 896 790B1FB62A41938F0074CF00 /* UIImage+CNLiveExtensions.swift in Sources */,
  897 + 19123FC12ABC11170075C883 /* CNWebViewController.swift in Sources */,
894 898 790D019D2A2DCBD000C5978D /* UIView+CNLiveExtensions.swift in Sources */,
895 899 7C7C62F62A4D72E9007A912E /* CNLiveIdentityDB.swift in Sources */,
896 900 790B1FB62A41938F0074CF00 /* UIImage+CNLiveExtensions.swift in Sources */,
... ...
metaCode/Classes/Main/HomePage/Controller/CNMetaCodeHomePageController.swift
... ... @@ -36,7 +36,17 @@ enum NetAPIStatus {
36 36 case notNetwork
37 37 }
38 38  
39   -class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDelegate, NewPagedFlowViewDataSource, CNCustomIndexViewDelegate,UIGestureRecognizerDelegate{
  39 +///垂直方向页面
  40 +enum VNumPage {
  41 + ///下滑页 第一页
  42 + case VNumPageDown
  43 + ///主要页面 第二页
  44 + case VNumPageMain
  45 + ///上滑页 第三页
  46 + case VNumPageUp
  47 +}
  48 +
  49 +class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDelegate, NewPagedFlowViewDataSource, CNCustomIndexViewDelegate,UIGestureRecognizerDelegate,WKNavigationDelegate{
40 50  
41 51  
42 52 ///NewPagedFlowView 开始滑动时的偏移量
... ... @@ -48,6 +58,9 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
48 58 // private var identityStatus: UserIdentityStatus = .notCertified
49 59 ///接口状态
50 60 private var NetApiStatus: NetAPIStatus = .apiError
  61 + ///接口状态
  62 + public var vNumPage: VNumPage = .VNumPageMain
  63 +
51 64  
52 65 // MARK: - 懒加载
53 66 ///数据源
... ... @@ -201,6 +214,15 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
201 214 }
202 215 override func viewWillAppear(_ animated: Bool) {
203 216 super.viewWillAppear(animated)
  217 + switch vNumPage {
  218 + case .VNumPageMain://中间主页
  219 + self.tabBarController?.tabBar.isHidden = false
  220 + case .VNumPageUp://上滑页
  221 + self.tabBarController?.tabBar.isHidden = true
  222 + case .VNumPageDown://下滑页
  223 + self.tabBarController?.tabBar.isHidden = true
  224 + }
  225 +
204 226  
205 227 print("uid = ",UserInfoManager.shared.userInfo.uid)
206 228  
... ... @@ -354,6 +376,8 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
354 376 bannerView?.superScrollView = flowView.scrollView
355 377 bannerView?.associatedVCView = self.view
356 378 bannerView?.delegate = self
  379 + bannerView?.upSlideView.webView.navigationDelegate = self
  380 + bannerView?.downSlideView.webView.navigationDelegate = self
357 381 let identityModel = dataArray[index] as! StandListModel
358 382 bannerView?.idModel = identityModel
359 383 return bannerView
... ... @@ -423,7 +447,7 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
423 447 }
424 448  
425 449  
426   - //MARK: - CNCustomIndexView 代理方法
  450 + //MARK: - CNCustomIndexView 代理方法 垂直方向滑动
427 451  
428 452 func customIndexViewWillBeiginScroll(scrollView: UIScrollView) {
429 453 self.view.height = KSreenHeight
... ... @@ -458,6 +482,17 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
458 482  
459 483  
460 484 func customIndexViewDidEndScroll(scrollView: UIScrollView) {
  485 + if scrollView.contentOffset.y == 0{//下滑页
  486 + self.tabBarController?.tabBar.isHidden = true
  487 + vNumPage = .VNumPageDown
  488 + }else if scrollView.contentOffset.y == KSreenHeight{//默认主页
  489 + self.tabBarController?.tabBar.isHidden = false
  490 + vNumPage = .VNumPageMain
  491 + }else if scrollView.contentOffset.y == KSreenHeight*2{//上滑页
  492 + self.tabBarController?.tabBar.isHidden = true
  493 + vNumPage = .VNumPageUp
  494 + }
  495 +
461 496 if scrollView.contentOffset.y == KSreenHeight {
462 497 self.view.height = self.tabBarY
463 498  
... ... @@ -473,6 +508,63 @@ class CNMetaCodeHomePageController:CNLiveBaseViewController, NewPagedFlowViewDel
473 508 }
474 509 }
475 510 }
  511 +
  512 + // MARK: - WKWebViewDelegate
  513 + // 页面开始加载时调用
  514 + func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
  515 + print("didStartProvisionalNavigation")
  516 + }
  517 + // 当内容开始返回时调用
  518 + func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
  519 + print("didCommit")
  520 + }
  521 + // 页面加载完成之后调用
  522 + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  523 + print("didFinish")
  524 + }
  525 + // 页面加载失败时调用
  526 + func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
  527 + print("didFailProvisionalNavigation")
  528 + }
  529 + // 接收到服务器跳转请求之后调用
  530 + func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
  531 + print("didReceiveServerRedirectForProvisionalNavigation")
  532 + }
  533 + // 在收到响应后,决定是否跳转 -> 默认允许
  534 + func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
  535 + print("decidePolicyFor")
  536 + //允许跳转
  537 + decisionHandler(.allow)
  538 + //不允许跳转
  539 +// decisionHandler(.cancel)
  540 + }
  541 + // 在发送请求之前,决定是否跳转 -> 默认允许
  542 + @available(iOS 13.0, *)
  543 + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {
  544 + print("decidePolicyFor")
  545 + let url:String = navigationAction.request.url!.absoluteString
  546 + print("navigationAction:\(navigationAction.navigationType.rawValue)")
  547 + print(url)
  548 + if(navigationAction.navigationType == .linkActivated){
  549 + let webVC = CNWebViewController()
  550 + webVC.url = url
  551 + currentViewController()?.navigationController?.pushViewController(webVC, animated: true)
  552 + decisionHandler(.cancel, preferences)
  553 + return
  554 + }else if(navigationAction.navigationType == .other){
  555 + if(url.contains("wjjh5.cnlive.com")){
  556 +
  557 + decisionHandler(.allow, preferences)
  558 + return
  559 + }else
  560 + {
  561 + decisionHandler(.cancel, preferences)
  562 + return
  563 + }
  564 + }
  565 + decisionHandler(.allow, preferences)
  566 + }
  567 +
476 568 //MARK: - 网络请求获取身份列表
477 569 func getUserIdentityApi()
478 570 {
... ...
metaCode/Classes/Main/HomePage/Controller/CNWebViewController.swift 0 → 100644
  1 +//
  2 +// CNWebViewController.swift
  3 +// metaCode
  4 +//
  5 +// Created by zx on 2023/9/21.
  6 +//
  7 +
  8 +import Foundation
  9 +import WebKit
  10 +
  11 +class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{
  12 +
  13 + lazy var webView: WKWebView = {
  14 + let webView = WKWebView.init(frame: CGRectMake(0, 0, Width, Height))
  15 + webView.scrollView.showsVerticalScrollIndicator = false
  16 + webView.scrollView.showsHorizontalScrollIndicator = false
  17 + webView.navigationDelegate = self
  18 + return webView
  19 + }()
  20 +
  21 + var _url:String?
  22 + var url:String? {
  23 + get{
  24 + return _url
  25 + }
  26 + set{
  27 + _url = newValue!
  28 + if (_url != ""){
  29 + let webUrl: URL! = URL.init(string: _url!)
  30 + webView.load(URLRequest.init(url:webUrl))
  31 + }
  32 + }
  33 + }
  34 +
  35 + override func viewDidLoad() {
  36 + super.viewDidLoad()
  37 + navigationBarHidden = false
  38 + self.view.addSubview(self.webView)
  39 + webView.snp.makeConstraints { make in
  40 + make.top.equalTo(get_system_nav_height())
  41 + make.left.right.bottom.equalToSuperview()
  42 + }
  43 +
  44 + }
  45 +
  46 + // MARK: - WKWebViewDelegate
  47 + // 页面开始加载时调用
  48 + func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
  49 + print("didStartProvisionalNavigation")
  50 + }
  51 + // 当内容开始返回时调用
  52 + func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
  53 + print("didCommit")
  54 + }
  55 + // 页面加载完成之后调用
  56 + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
  57 + print("didFinish")
  58 + titleName = webView.title!
  59 + }
  60 + // 页面加载失败时调用
  61 + func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
  62 + print("didFailProvisionalNavigation")
  63 + }
  64 + // 接收到服务器跳转请求之后调用
  65 + func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
  66 + print("didReceiveServerRedirectForProvisionalNavigation")
  67 + }
  68 + // 在收到响应后,决定是否跳转 -> 默认允许
  69 + func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Void) {
  70 + print("decidePolicyFor")
  71 + //允许跳转
  72 + decisionHandler(.allow)
  73 + //不允许跳转
  74 + // decisionHandler(.cancel)
  75 + }
  76 + // 在发送请求之前,决定是否跳转 -> 默认允许
  77 + @available(iOS 13.0, *)
  78 + func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {
  79 +
  80 + decisionHandler(.allow, preferences)
  81 + }
  82 +}
... ...
metaCode/Classes/Main/HomePage/View/CNCustomIndexView.swift
... ... @@ -184,6 +184,7 @@ class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChange
184 184 collectionView.backgroundColor = .clear
185 185 collectionView.backAction = {[weak self] in
186 186 self?.baseScrollView.setContentOffset(CGPoint(x: 0, y: (self!.baseScrollView.height)), animated: true)
  187 + currentViewController()?.tabBarController?.tabBar.isHidden = false
187 188 self?.superScrollView?.isScrollEnabled = true
188 189  
189 190 let time = DispatchTime.now() + 0.5
... ... @@ -228,6 +229,7 @@ class CNCustomIndexView:PGIndexBannerSubiew, UIScrollViewDelegate, WJColorChange
228 229 topNavView.closeAction = { [weak self ] in
229 230 self!.baseScrollView.setContentOffset(CGPoint(x: 0, y: self!.baseScrollView.height), animated: true)
230 231 self?.superScrollView?.isScrollEnabled = true
  232 + currentViewController()?.tabBarController?.tabBar.isHidden = false
231 233 }
232 234 return topNavView
233 235 }()
... ...
metaCode/Classes/Main/HomePage/View/CNDownSlideView.swift
... ... @@ -54,7 +54,6 @@ class CNDownSlideView:UIView{
54 54 }
55 55 set{
56 56 _url = newValue!
57   -// _url = "https://www.baidu.com"
58 57 if (_url != ""){
59 58 let webUrl: URL! = URL.init(string: _url!)
60 59 webView.load(URLRequest.init(url:webUrl))
... ...