-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecondViewController.swift
90 lines (72 loc) · 3.77 KB
/
SecondViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// ViewController.swift
// Warning
//
// Created by 이주송 on 2022/09/19.
//
import UIKit
import WebKit
class SecondViewController: UIViewController,WKUIDelegate,WKNavigationDelegate {
@IBOutlet weak var webView: WKWebView!
lazy var leftButton: UIBarButtonItem = {
let button = UIBarButtonItem(image: UIImage(systemName: "chevron.left"), style: .plain, target: self, action: #selector(backButtonPressed(_:)))
button.tag = 1
return button
}()
lazy var rightButton: UIBarButtonItem = {
let button = UIBarButtonItem(image: UIImage(systemName: "chair"), style: .plain, target: self, action: #selector(buttonPressed(_:)))
button.tag = 2
return button
}()
@objc private func buttonPressed(_ sender: Any) {
if let button = sender as? UIBarButtonItem {
switch button.tag {
case 1:
print("뒤로가기")
case 2:
print("예약버튼 클릭")
default:
print("error")
}
}
}
@objc private func backButtonPressed(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
override func viewWillAppear(_ animated: Bool) {
self.navigationItem.rightBarButtonItem = self.rightButton
self.navigationItem.leftBarButtonItem = self.leftButton
}
override func loadView() {
super.loadView()
webView = WKWebView(frame: self.view.frame)
webView.uiDelegate = self
webView.navigationDelegate = self
self.view = self.webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "http://mobileid.kw.ac.kr/seatweb/roomview5.asp?room_no=2")
let request = URLRequest(url: url!)
//self.webView?.allowsBackForwardNavigationGestures = true //뒤로가기 제스쳐 허용
webView.configuration.preferences.javaScriptEnabled = true //자바스크립트 활성화
webView.load(request)
}
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } //모달창 닫힐때 앱 종료현상 방지.
//alert 처리
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void){
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in completionHandler() }))
self.present(alertController, animated: true, completion: nil) }
//confirm 처리
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "취소", style: .default, handler: { (action) in completionHandler(false) }))
alertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in completionHandler(true) }))
self.present(alertController, animated: true, completion: nil) }
// href="_blank" 처리
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil { webView.load(navigationAction.request) }
return nil }
}