我的导航栏在我的应用中不可见

时间:2020-05-12 09:32:33

标签: swift xcode uinavigationbar

我正在尝试在我的应用程序中设置一个导航栏和一个WKWebview,该Webview存在,但是我看不到导航栏不可见。我究竟做错了什么?

我现在编辑了代码,它可以很好地工作,这就是问题所在。

这是我的代码

    class MyController:UIViewController, WKNavigationDelegate{

var webView: WKWebView!

@IBOutlet weak var barView: UIView!

required init(coder aDecoder: NSCoder) {
    self.webView = WKWebView(frame: CGRect.zero)
    super.init(coder: aDecoder)!

       self.webView.navigationDelegate = self
   }


override func viewDidLoad() {
       super.viewDidLoad()
 barView.frame = CGRect(x:0, y: 0, width: view.frame.width, height: 40)
    view.insertSubview(webView, belowSubview: barView)


    webView.translatesAutoresizingMaskIntoConstraints = false
    let height = NSLayoutConstraint(item: webView, attribute: .height, relatedBy: .equal, toItem: view, attribute: .height, multiplier: 1, constant: 0)
    let width = NSLayoutConstraint(item: webView, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 1, constant: 0)
    view.addConstraints([height, width])

    if((UserDefaults.standard.object(forKey:"language")as? String ?? "") == "en"){

        let url = URL(string: "myurl")!
        webView.load(URLRequest(url: url))
                     }
                     else{

        let url = URL(string: "https://myurl")!
        webView.load(URLRequest(url: url))
                            }


   }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    barView.frame = CGRect(x:0, y: 0, width: size.width, height: 40)
}
override func viewWillAppear(_ animated: Bool) {

   }

   override func didReceiveMemoryWarning() {
       super.didReceiveMemoryWarning()
       // Dispose of any resources that can be recreated.


   }

@IBAction func btnSideMenuActn(_ sender: UIButton) {
      self.pushViewControl(ViewControl:"SideMenuController")
  }

    }

0 个答案:

没有答案