HelpVC.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // HelpVC.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 24/03/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. class HelpVC: UIViewController {
  11. @IBOutlet weak var dropdown1: UIImageView!
  12. @IBOutlet weak var lineWv1: UIView!
  13. @IBOutlet weak var wv1: WKWebView!
  14. // View Lifecycles
  15. override var preferredStatusBarStyle: UIStatusBarStyle {
  16. return .lightContent
  17. }
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. let html1 = """
  21. <html>
  22. <meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0;'>
  23. <head>
  24. <style type='text/css'>
  25. html {-webkit-text-size-adjust: none;}
  26. body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; padding: 8px;}
  27. .pixel {font-size: 14px}
  28. </style>
  29. </head>
  30. <body>
  31. <p class="pixel" align="justify" class="center">
  32. <b style="font-size:15px;">Direktorat Standardisasi Perangkat Pos dan Informatika</b>
  33. <br>
  34. Direktorat Jenderal Sumber Daya dan Perangkat Pos dan Informatika<br>
  35. Kementerian Komunikasi dan Informatika - Republik Indonesia<br><br>
  36. <b>Loket Pelayanan Terpadu SDPPI</b><br>
  37. Wisma Antara Lantai 1<br>
  38. Jl. Medan Merdeka Selatan No.17, Gambir, Jakarta Pusat, DKI Jakarta<br>
  39. <i class="icon-phone bigger-100"></i> Phone : 159<br>
  40. <i class="icon-envelope bigger-100"></i> Email : <a href="mailto:kontak@kominfo.go.id" target="_blank">kontak@kominfo.go.id</a><br>
  41. </p>
  42. </body>
  43. </html>
  44. """
  45. wv1.navigationDelegate = self
  46. wv1.loadHTMLString(html1, baseURL: nil)
  47. }
  48. @IBAction func onTitleOneTapped(_ sender: Any) {
  49. if self.wv1.isHidden {
  50. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  51. self.lineWv1.isHidden = false
  52. self.lineWv1.layoutIfNeeded()
  53. self.wv1.isHidden = false
  54. self.wv1.layoutIfNeeded()
  55. self.dropdown1.rotates(-.pi)
  56. })
  57. } else {
  58. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  59. self.lineWv1.isHidden = true
  60. self.lineWv1.layoutIfNeeded()
  61. self.wv1.isHidden = true
  62. self.wv1.layoutIfNeeded()
  63. self.dropdown1.rotates(0.0)
  64. })
  65. }
  66. }
  67. }
  68. extension UIView {
  69. func rotates(_ toValue: CGFloat, duration: CFTimeInterval = 0.3) {
  70. let animation = CABasicAnimation(keyPath: "transform.rotation")
  71. animation.toValue = toValue
  72. animation.duration = duration
  73. animation.isRemovedOnCompletion = false
  74. animation.fillMode = CAMediaTimingFillMode.forwards
  75. self.layer.add(animation, forKey: nil)
  76. }
  77. }
  78. extension HelpVC: WKNavigationDelegate {
  79. func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
  80. if navigationAction.navigationType == .linkActivated {
  81. guard let url = navigationAction.request.url else {
  82. decisionHandler(.allow)
  83. return
  84. }
  85. let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
  86. if components?.scheme == "http" || components?.scheme == "https" || components?.scheme == "mailto"
  87. {
  88. if UIApplication.shared.canOpenURL(url) {
  89. if #available(iOS 10.0, *) {
  90. UIApplication.shared.open(url)
  91. } else {
  92. UIApplication.shared.openURL(url)
  93. }
  94. decisionHandler(.cancel)
  95. } else {
  96. decisionHandler(.allow)
  97. }
  98. } else {
  99. decisionHandler(.allow)
  100. }
  101. } else {
  102. decisionHandler(.allow)
  103. }
  104. }
  105. }