     override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
         if (context == &KVO.context && keyPath == KVO.ScrollViewPath.contentOffset && object as? UIScrollView == scrollView) {
             var offset: CGFloat
+            var topInsetY: CGFloat
+            if #available(iOS 11, *) {
+                topInsetY = scrollView!.adjustedContentInset.top
+            } else {
+                topInsetY = scrollView!.contentInset.top
+            }
             switch position {
             case .top:
-                offset = previousScrollViewOffset.y + defaultInsets.top
+                offset = previousScrollViewOffset.y + topInsetY
                 
             case .bottom:
                 if scrollView!.contentSize.height > scrollView!.bounds.height {
-                    offset = scrollView!.contentSize.height - previousScrollViewOffset.y - scrollView!.bounds.height
+                    offset = scrollView!.contentSize.height - previousScrollViewOffset.y - scrollView!.bounds.height + topInsetY
                 } else {
-                    offset = scrollView!.contentSize.height - previousScrollViewOffset.y
+                    offset = scrollView!.contentSize.height - previousScrollViewOffset.y + topInsetY
                 }
             }
             let refreshViewHeight = refreshView.frame.size.height

        willSet {
            if #available(iOS 11.0, *) {
                scrollView?.removeAdjustedContentInsetsHandler(forPosition: position)
            } 
            removeScrollViewObserving()
        }
        didSet {

                    scrollView?.contentInset = self.scrollViewDefaultInsets
                    state = .initial
                }
                
            default: break
            }
        }
