I want to set a safety zone by device. My web view is set to SafeArea above
, SuperView below
. After the iPhone X
series, the value of Y
is 44
because of the notch
area. But for the iPhone 6
and iPhone 8
, 44
is too wide. How do I adjust it?
@IBOutlet var WKWebView: FullScreenWKWebView!
...
let config = WKWebViewConfiguration()
contentController.add(self, name: "goApp")
config.userContentController = contentController
WKWebView = FullScreenWKWebView(frame: WKWebView.frame, configuration: config)
WKWebView.uiDelegate = self
WKWebView.navigationDelegate = self
WKWebView.scrollView.delegate = self
view.addSubview(WKWebView)
view.addSubview(indicator)
...
class FullScreenWKWebView: WKWebView {
override var safeAreaInsets: UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
I want to set the Top SafeArea area by device.
I am trying things, but is unsuccessful.
I cannot set the top area of WKWebView
as a safety zone unconditionally. Because the safety area includes the NavigationController
Bar Area. But I don't use the NavigationController
. Therefore, it is not possible to set the safety zone as a constraint.
So I solved the problem by separating by device size.
let screenHeight = UIScreen.main.bounds.size.height
if screenHeight > 667 {
WKWebView = FullScreenWKWebView(frame: CGRect( x: 0, y: 44, width: WKWebView.frame.width, height: WKWebView.frame.height - 44 ), configuration: config)
} else {
WKWebView = FullScreenWKWebView(frame: CGRect( x: 0, y: 20, width: WKWebView.frame.width, height: WKWebView.frame.height - 20 ), configuration: config)
}