   }
 
   override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval) {
-    let orientation: UIInterfaceOrientation = toInterfaceOrientation
-    if UIDevice.current.userInterfaceIdiom == .phone {
-      let screenRect = UIScreen.main.bounds
-      let size = CGFloat.maximum(screenRect.size.width, screenRect.size.height)
-      if size > 568.0 {
-        // TODO: Refactor since duplicated in viewDidLoad()
-        // Navbar for iPhone 6 & 6 Plus
-        let image: UIImage
-        if UIInterfaceOrientationIsPortrait(orientation) {
-          image = #imageLiteral(resourceName: "kmwb-navbar-Portrait.png")
-        } else {
-          image = #imageLiteral(resourceName: "kmwb-navbar-Landscape-568h.png")
-        }
-        let bgImg = image.resizableImage(
-          withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch)
-        navigationController?.navigationBar.setBackgroundImage(bgImg, for: UIBarMetrics.default)
-      }
-    } else {
-      let image: UIImage
-      if UIInterfaceOrientationIsPortrait(orientation) {
-        image = #imageLiteral(resourceName: "kmwb-navbar-Portrait.png")
-      } else {
-        image = #imageLiteral(resourceName: "kmwb-navbar-Landscape.png")
-      }
-      navigationController?.navigationBar.setBackgroundImage(image, for: UIBarMetrics.default)
+    if let navbarBackground = navbarBackground {
+      navbarBackground.setOrientation(toInterfaceOrientation)
     }
   }
 

    webView.scalesPageToFit = true

    // Setup NavigationBar
    let screenRect = UIScreen.main.bounds
    let orientation = UIApplication.shared.statusBarOrientation
    if UIDevice.current.userInterfaceIdiom == .phone {
      let size = CGFloat.maximum(screenRect.size.height, screenRect.size.width)
      if size > 568.0 {
        // Navbar for iPhone 6 & 6 Plus
        let image: UIImage
        if UIInterfaceOrientationIsPortrait(orientation) {
          image = #imageLiteral(resourceName: "kmwb-navbar-Portrait.png")
        } else {
          image = #imageLiteral(resourceName: "kmwb-navbar-Landscape-568h.png")
        }
        let bgImg = image.resizableImage(
          withCapInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), resizingMode: .stretch)
        navBar.setBackgroundImage(bgImg, for: UIBarMetrics.default)
      } else if size == 568 {
        // Navbar for iPhone and iPod Touch with 4" Display
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Portrait.png"),
                                  for: UIBarMetrics.default)
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Landscape-568h.png"),
                                  for: UIBarMetrics.compact)
      } else if size < 568.0 {
        // Navbar for iPhone and iPod Touch with 3.5" Display
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Portrait.png"),
                                  for: UIBarMetrics.default)
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Landscape.png"),
                                  for: UIBarMetrics.compact)
      }
    } else {
      // Navbar for iPad
      if UIInterfaceOrientationIsPortrait(orientation) {
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Portrait.png"), for: UIBarMetrics.default)
      } else {
        navBar.setBackgroundImage(#imageLiteral(resourceName: "kmwb-navbar-Landscape.png"), for: UIBarMetrics.default)
      }
    }

    // Setup address field
    let addressFrame = CGRect(x: 10, y: 4.0, width: navBar.frame.size.width - 20, height: 28)

  @IBOutlet var globeButton: UIBarButtonItem!
  @IBOutlet var closeButton: UIBarButtonItem!

  var navbarBackground: KMNavigationBarBackgroundView!
  var fontFamily = UIFont.systemFont(ofSize: UIFont.systemFontSize).fontName
  private var newFontFamily = ""

