         
         if let scrollView = targetView {
             let insetTop: CGFloat
-            
+            let safeAreaTop: CGFloat
+            if #available(iOS 11.0, *) {
+                safeAreaTop = scrollView.safeAreaInsets.top
+            } else {
+                safeAreaTop = 0
+            }
+
             if scrollView.superview?.superview == nil {
                 insetTop = 0
             } else {
-                insetTop = initialInsetTop
-            }
-            
-            if scrollView.contentInset.top > insetTop {
+                insetTop = initialInsetTop + safeAreaTop
+            }
+            
+            if scrollView.contentInset.top + safeAreaTop > 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
                
                if beforeOffsetY < -insetTop {
                    indicator.layer.add(refreshEndAnimation(), forKey: Me.ScaleAnimationKey)

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

        return offsetY
    }
    
