Skip to content

Commit

Permalink
Ios 11的适配
Browse files Browse the repository at this point in the history
  • Loading branch information
CharmingZzz committed Aug 29, 2017
1 parent c1a3650 commit 4e8be61
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MJRefresh/Base/MJRefreshBackFooter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions MJRefresh/Base/MJRefreshComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ - (void)willMoveToSuperview:(UIView *)newSuperview
// 设置永远支持垂直弹簧效果
_scrollView.alwaysBounceVertical = YES;
// 记录UIScrollView最开始的contentInset
_scrollViewOriginalInset = _scrollView.contentInset;
_scrollViewOriginalInset = _scrollView.mj_inset;

// 添加监听
[self addObservers];
Expand Down Expand Up @@ -271,4 +271,4 @@ - (CGFloat)mj_textWith {
}
return stringWidth;
}
@end
@end
2 changes: 1 addition & 1 deletion MJRefresh/Base/MJRefreshHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions MJRefresh/UIScrollView+MJExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#import <UIKit/UIKit.h>

@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;
Expand Down
24 changes: 22 additions & 2 deletions MJRefresh/UIScrollView+MJExtension.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e8be61

Please sign in to comment.