Title bar

This commit is contained in:
James Magahern
2020-07-29 14:16:25 -07:00
parent 9f506c879f
commit f330293606
6 changed files with 101 additions and 1 deletions

View File

@@ -11,6 +11,8 @@ import WebKit
class BrowserView: UIView
{
let titlebarView = TitlebarView()
var toolbarView: ToolbarView? {
didSet { addSubview(toolbarView!) }
}
@@ -32,6 +34,8 @@ class BrowserView: UIView
convenience init() {
self.init(frame: .zero)
addSubview(titlebarView)
keyboardWillShowObserver = NotificationCenter.default.publisher(for: UIWindow.keyboardWillShowNotification).sink { notification in
if let keyboardFrame = notification.userInfo?[UIWindow.keyboardFrameEndUserInfoKey] as? CGRect {
self.keyboardLayoutOffset = self.bounds.height - keyboardFrame.minY
@@ -59,5 +63,21 @@ class BrowserView: UIView
toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize)
toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - keyboardLayoutOffset)
}
bringSubviewToFront(titlebarView)
var titlebarHeight: CGFloat = 24.0
titlebarHeight += safeAreaInsets.top
titlebarView.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width, height: titlebarHeight))
// Fix web view content insets
webView?.scrollView.automaticallyAdjustsScrollIndicatorInsets = false
var webViewContentInset = UIEdgeInsets()
webViewContentInset.top = titlebarView.frame.height
webViewContentInset.bottom = toolbarView?.frame.height ?? 0
webView?.scrollView.contentInset = webViewContentInset
webView?.scrollView.scrollIndicatorInsets = webViewContentInset
}
}