     }
 
     func hideToolbars(#animated: Bool, completion: ((finished: Bool) -> Void)? = nil) {
+        toolbarState = .Collapsed
         let animationDistance = headerFrame.height - abs(headerTopOffset)
-        let durationRatio = abs(headerTopOffset / headerFrame.height)
+        let durationRatio = abs((headerFrame.height + headerTopOffset) / headerFrame.height)
         let actualDuration = NSTimeInterval(ToolbarBaseAnimationDuration * durationRatio)
         self.animateToolbarsWithOffsets(
             animated: animated,


    private var lastContentOffset: CGFloat = 0
    private var scrollDirection: ScrollDirection = .Down

    override init() {
        super.init()
    }

    func showToolbars(#animated: Bool, completion: ((finished: Bool) -> Void)? = nil) {
        let durationRatio = abs(headerTopOffset / headerFrame.height)
        let actualDuration = NSTimeInterval(ToolbarBaseAnimationDuration * durationRatio)
        self.animateToolbarsWithOffsets(

            completion?(finished: true)
        }
    }

    func checkScrollHeightIsLargeEnoughForScrolling() -> Bool {
        return (scrollViewHeight + 2 * UIConstants.ToolbarHeight) < scrollView?.contentSize.height
    }
}

extension BrowserScrollingController: UIGestureRecognizerDelegate {
