diff --git a/MJRefresh/Base/MJRefreshBackFooter.m b/MJRefresh/Base/MJRefreshBackFooter.m index 83978adc..83190056 100644 --- a/MJRefresh/Base/MJRefreshBackFooter.m +++ b/MJRefresh/Base/MJRefreshBackFooter.m @@ -31,7 +31,7 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change // 如果正在刷新,直接返回 if (self.state == MJRefreshStateRefreshing) return; - _scrollViewOriginalInset = self.scrollView.contentInset; + _scrollViewOriginalInset = self.scrollView.mj_inset; // 当前的contentOffset CGFloat currentOffsetY = self.scrollView.mj_offsetY; diff --git a/MJRefresh/Base/MJRefreshComponent.m b/MJRefresh/Base/MJRefreshComponent.m index fec5ed7f..5ae8139f 100644 --- a/MJRefresh/Base/MJRefreshComponent.m +++ b/MJRefresh/Base/MJRefreshComponent.m @@ -65,7 +65,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview // 设置永远支持垂直弹簧效果 _scrollView.alwaysBounceVertical = YES; // 记录UIScrollView最开始的contentInset - _scrollViewOriginalInset = _scrollView.contentInset; + _scrollViewOriginalInset = _scrollView.mj_inset; // 添加监听 [self addObservers]; @@ -271,4 +271,4 @@ - (CGFloat)mj_textWith { } return stringWidth; } -@end \ No newline at end of file +@end diff --git a/MJRefresh/Base/MJRefreshHeader.m b/MJRefresh/Base/MJRefreshHeader.m index 070cea6c..6dda1771 100644 --- a/MJRefresh/Base/MJRefreshHeader.m +++ b/MJRefresh/Base/MJRefreshHeader.m @@ -66,7 +66,7 @@ - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change } // 跳转到下一个控制器时,contentInset可能会变 - _scrollViewOriginalInset = self.scrollView.contentInset; + _scrollViewOriginalInset = self.scrollView.mj_inset; // 当前的contentOffset CGFloat offsetY = self.scrollView.mj_offsetY; diff --git a/MJRefresh/UIScrollView+MJExtension.h b/MJRefresh/UIScrollView+MJExtension.h index 734110f3..dd70d088 100644 --- a/MJRefresh/UIScrollView+MJExtension.h +++ b/MJRefresh/UIScrollView+MJExtension.h @@ -10,6 +10,8 @@ #import @interface UIScrollView (MJExtension) +@property (readonly, nonatomic) UIEdgeInsets mj_inset; + @property (assign, nonatomic) CGFloat mj_insetT; @property (assign, nonatomic) CGFloat mj_insetB; @property (assign, nonatomic) CGFloat mj_insetL; diff --git a/MJRefresh/UIScrollView+MJExtension.m b/MJRefresh/UIScrollView+MJExtension.m index 6a13f5fe..29f4cae6 100644 --- a/MJRefresh/UIScrollView+MJExtension.m +++ b/MJRefresh/UIScrollView+MJExtension.m @@ -12,28 +12,48 @@ @implementation UIScrollView (MJExtension) +- (UIEdgeInsets)mj_inset +{ +#ifdef __IPHONE_11_0 + if(@available(iOS 11.0, *)){ + return self.adjustedContentInset; + } +#endif + return self.contentInset; +} + - (void)setMj_insetT:(CGFloat)mj_insetT { UIEdgeInsets inset = self.contentInset; inset.top = mj_insetT; +#ifdef __IPHONE_11_0 + if(@available(iOS 11.0, *)){ + inset.top -= (self.adjustedContentInset.top - self.contentInset.top); + } +#endif self.contentInset = inset; } - (CGFloat)mj_insetT { - return self.contentInset.top; + return self.mj_inset.top; } - (void)setMj_insetB:(CGFloat)mj_insetB { UIEdgeInsets inset = self.contentInset; inset.bottom = mj_insetB; +#ifdef __IPHONE_11_0 + if(@available(iOS 11.0, *)){ + inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom); + } +#endif self.contentInset = inset; } - (CGFloat)mj_insetB { - return self.contentInset.bottom; + return self.mj_inset.bottom; } - (void)setMj_insetL:(CGFloat)mj_insetL