     
     fileprivate func scrollOffset(_ scrollView: UIScrollView) -> CGFloat {
         var offsetY = scrollView.contentOffset.y
-        offsetY += initialInsetTop
-        
+        if #available(iOS 11.0, *) {
+            offsetY += initialInsetTop + scrollView.safeAreaInsets.top
+        } else {
+            offsetY += initialInsetTop
+        }
+
         return offsetY
     }
     

        
        if let scrollView = targetView {
            let insetTop: CGFloat
            
            if scrollView.superview?.superview == nil {
                insetTop = 0
            } else {
                insetTop = initialInsetTop
            }
            
            if scrollView.contentInset.top > insetTop {
                let completionBlock: (() -> Void) = {
                    self.indicator.stopAnimation(false) { indicator in
                        indicator.layer.removeAnimation(forKey: Me.ScaleAnimationKey)

                }
                
                let beforeOffsetY = scrollView.contentOffset.y
                scrollView.contentInset.top = insetTop - safeAreaTop
                
                if beforeOffsetY < -insetTop {
                    indicator.layer.add(refreshEndAnimation(), forKey: Me.ScaleAnimationKey)
