 			var newContentOffset = scrollView.contentOffset
 			newContentOffset.y -= deltaY
 			
-			let contentInset = scrollView.contentInset
+			let contentInset = scrollViewContentInset
 			let top = contentInset.top + deltaY
 			
 			UIView.animate(withDuration: 0.2, animations: {


		if scrolledToTop {
			var offset = scrollView.contentOffset
			offset.y = -scrollView.contentInset.top
			scrollView.contentOffset = offset
		}
		

		return true
	}

    //MARK: iOS 11 handling (adjustedContentInset, safeAreaInsets)
    
    var scrollViewContentInset: UIEdgeInsets {
        if #available(iOS 11.0, *) {
            return scrollView.adjustedContentInset
        } else {
            return scrollView.contentInset
        }
    }
    
    fileprivate func adjustTopInset(_ top: CGFloat) -> CGFloat {
        if #available(iOS 11.0, *) {
            return top - scrollView.safeAreaInsets.top  // subtract safeAreaInsets for ios11
        }
        return top
    }
}
