forked from turbolinks/turbolinks-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisitableViewController.swift
62 lines (48 loc) · 2.06 KB
/
VisitableViewController.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
import UIKit
open class VisitableViewController: UIViewController, Visitable {
open weak var visitableDelegate: VisitableDelegate?
open var visitableURL: URL!
public convenience init(url: URL) {
self.init()
self.visitableURL = url
}
// MARK: Visitable View
open private(set) lazy var visitableView: VisitableView! = {
let view = VisitableView(frame: CGRect.zero)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
fileprivate func installVisitableView() {
view.addSubview(visitableView)
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[view]|", options: [], metrics: nil, views: [ "view": visitableView! ]))
view.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[view]|", options: [], metrics: nil, views: [ "view": visitableView! ]))
}
// MARK: Visitable
open func visitableDidRender() {
self.title = visitableView.webView?.title
}
// MARK: View Lifecycle
open override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
installVisitableView()
}
open override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
visitableDelegate?.visitableViewWillAppear(self)
}
open override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
visitableDelegate?.visitableViewDidAppear(self)
}
/*
If the visitableView is a child of the main view, and anchored to its top and bottom, then it's
unlikely you will need to customize the layout. But more complicated view hierarchies and layout
may require explicit control over the contentInset. Below is an example of setting the contentInset
to the layout guides.
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
visitableView.contentInset = UIEdgeInsets(top: topLayoutGuide.length, left: 0, bottom: bottomLayoutGuide.length, right: 0)
}
*/
}