MailViewController.swift 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // MailViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 林玲 on 2017/10/20.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. import Alamofire
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import CocoaLumberjack
  15. class MailViewController: BaseWebViewUIViewController {
  16. var app:O2App?
  17. // 首页显示门户 默认没有NavigationBar
  18. var isIndexShow:Bool = false
  19. // 门户内部是否有显示NavigationBar
  20. var hasInnerBar:Bool = false
  21. override func viewDidLoad() {
  22. super.viewDidLoad()
  23. //监听清除缓存之后需要重载
  24. NotificationCenter.default.addObserver(self, selector: #selector(loadDetailSubject), name: OONotification.reloadPortal.notificationName, object: nil)
  25. if self.isIndexShow {
  26. self.navigationItem.leftBarButtonItems = []
  27. }else {
  28. self.title = self.app?.title ?? ""
  29. let closeBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  30. closeBtn.setImage(UIImage(named: "icon_off_white2"), for: .normal)
  31. closeBtn.addTapGesture { (tap) in
  32. self.navigationController?.dismiss(animated: true, completion: nil)
  33. }
  34. let closeItem = UIBarButtonItem(customView: closeBtn)
  35. let backBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
  36. backBtn.setImage(UIImage(named: "icon_fanhui"), for: .normal)
  37. backBtn.addTapGesture { (tap) in
  38. self.goBack(isBackBtn: true)
  39. }
  40. let backItem = UIBarButtonItem(customView: backBtn)
  41. self.navigationItem.leftBarButtonItems = [backItem, closeItem]
  42. }
  43. self.theWebView()
  44. self.delegate = self
  45. }
  46. override func viewWillAppear(_ animated: Bool) {
  47. if self.isIndexShow || self.hasInnerBar {
  48. if #available(iOS 13.0, *) {
  49. if let frame = UIApplication.shared.keyWindow?.windowScene?.statusBarManager?.statusBarFrame {
  50. let statusBar = UIView(frame: frame)
  51. statusBar.backgroundColor = base_color
  52. UIApplication.shared.keyWindow?.addSubview(statusBar)
  53. }
  54. }else {
  55. let statusBarWindow : UIView = UIApplication.shared.value(forKey: "statusBarWindow") as! UIView
  56. let statusBar : UIView = statusBarWindow.value(forKey: "statusBar") as! UIView
  57. if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
  58. statusBar.backgroundColor = base_color
  59. }
  60. }
  61. self.navigationController?.setNavigationBarHidden(true, animated: true)
  62. }
  63. }
  64. override func viewWillDisappear(_ animated: Bool) {
  65. self.navigationController?.setNavigationBarHidden(false, animated: false)
  66. }
  67. override func didReceiveMemoryWarning() {
  68. super.didReceiveMemoryWarning()
  69. // Dispose of any resources that can be recreated.
  70. }
  71. override func theWebView(){
  72. super.theWebView()
  73. self.view = webView
  74. self.webView.allowsBackForwardNavigationGestures = true
  75. loadDetailSubject()
  76. }
  77. @objc func loadDetailSubject(){
  78. if let url = self.app?.vcName?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
  79. if let req = Alamofire.request(url).request {
  80. self.webView?.load(req)
  81. }else {
  82. self.showError(title: "URL请求异常")
  83. }
  84. }else {
  85. self.showError(title: "没有获取到URL")
  86. }
  87. }
  88. func goBack(isBackBtn: Bool) {
  89. if self.webView?.canGoBack ?? false {
  90. self.webView?.goBack()
  91. }else {
  92. if isBackBtn {
  93. self.navigationController?.dismiss(animated: true, completion: nil)
  94. }
  95. }
  96. }
  97. /*
  98. // MARK: - Navigation
  99. // In a storyboard-based application, you will often want to do a little preparation before navigation
  100. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  101. // Get the new view controller using segue.destinationViewController.
  102. // Pass the selected object to the new view controller.
  103. }
  104. */
  105. }
  106. extension MailViewController: BaseWebViewUIViewControllerJSDelegate {
  107. func closeUIViewWindow() {
  108. DDLogDebug("关闭啦。。。。。。。。。。。。。。")
  109. self.navigationController?.dismiss(animated: true, completion: nil)
  110. }
  111. func actionBarLoaded(show: Bool) {
  112. DDLogDebug("actionBar 显示了。。。。\(show)。")
  113. if(show) {
  114. self.hasInnerBar = true
  115. self.navigationController?.setNavigationBarHidden(true, animated: true)
  116. }
  117. }
  118. }