Siv*_*ami 7 uinavigationbar ios swift wkwebview
在视图控制器中,我正在加载启用了大导航标题的网络视图(WKWebview)。问题是它在 webview 加载之前完美地显示了大的导航栏和标题,一旦 webview 加载它就会缩小到正常。任何帮助,将不胜感激。
提前致谢...!
斯威夫特4、斯威夫特5:
viewLayoutMarginsDidChange()我们可以改变navigationBar的高度。viewLayoutMarginsDidChange()调用以通知视图控制器其根视图的布局边距已更改。每次当 navigationBar 高度发生变化时,都会调用此方法。下面的代码对我有用
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
private var webView: WKWebView!
var didChange = false //Set true when we have to update navigationBar height in viewLayoutMarginsDidChange()
override func viewLayoutMarginsDidChange() {
if didChange {
print("Height : - \(self.navigationController?.navigationBar.frame.size.height)")
// set NavigationBar Height here
self.navigationController!.navigationBar.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 96.0)
didChange.toggle()
}
}
override func viewDidLoad() {
super.viewDidLoad()
let appearance = UIBarButtonItem.appearance()
appearance.setBackButtonTitlePositionAdjustment(UIOffset.init(horizontal: 0.0, vertical: -60), for: .default)
self.navigationItem.title = "WebView"
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.navigationBar.tintColor = UIColor.black
self.navigationController?.navigationBar.prefersLargeTitles = true
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
webView.navigationDelegate = self
view = webView
let myURL = URL(string:"https://google.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Did Start")
//webView page starts loading
didChange = true
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1682 次 |
| 最近记录: |