   func setToolbarVisibilty(hidden: Bool) {
     if let nav = navigationController {
       nav.setNavigationBarHidden(hidden, animated: true)
-      nav.setToolbarHidden(hidden, animated: true)
+      if (showToolBar) {
+        nav.setToolbarHidden(hidden, animated: true)
+      }
     }
   }
   

}


//MARK: implementation of UIPageViewControllerDataSource
extension ImageViewer: UIPageViewControllerDataSource {
  
  public func pageViewController(_ pageViewController: UIPageViewController,

      return nil
    }
  }
    
}

//MARK: UIPageViewControllerDelegate
extension ImageViewer: UIPageViewControllerDelegate {
    
  //This updates the currentIndex after the transition.
  public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
    
    guard completed else { return }
    let pageContentViewController = pageViewController.viewControllers![0] as! ImageViewController
    let index = pageContentViewController.index
        
    currentIndex = index
  }
}


