Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改bug,self.mj_x = -_scrollView.mj_insetL 不生效 #1293

Merged
merged 1 commit into from
May 27, 2019

Conversation

wanshanhu79
Copy link
Contributor

修改bug,在scrollview的contentInset的left有值时刷新内容不居中,您已经加了相关逻辑,但未生效。

@implementation MJRefreshComponent
- (void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    // 如果不是UIScrollView,不做任何事情
    if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return;
    
    // 旧的父控件移除监听
    [self removeObservers];
    
    if (newSuperview) { // 新的父控件
        // 设置宽度
        self.mj_w = newSuperview.mj_w;
        // 设置位置
        self.mj_x = -_scrollView.mj_insetL;
        
        // 记录UIScrollView
        _scrollView = (UIScrollView *)newSuperview;
        // 设置永远支持垂直弹簧效果
        _scrollView.alwaysBounceVertical = YES;
        // 记录UIScrollView最开始的contentInset
        _scrollViewOriginalInset = _scrollView.mj_inset;
        
        // 添加监听
        [self addObservers];
    }
}
@end

self.mj_x = -_scrollView.mj_insetL; 时,_scrollView 还没有值,所以 self.mj_x 永远是0。不会根据 scrollViewmj_insetL 反向移动。
如果 scrollView 设置了 contentInsetheaderfooter 的内容都会偏移 self.mj_x,不居中。

调整如下,移动代码顺序

  // 设置宽度
        self.mj_w = newSuperview.mj_w;
        
        // 记录UIScrollView
        _scrollView = (UIScrollView *)newSuperview;
        
        // 设置位置
        self.mj_x = -_scrollView.mj_insetL;
    
        // 设置永远支持垂直弹簧效果
        _scrollView.alwaysBounceVertical = YES;
        // 记录UIScrollView最开始的contentInset
        _scrollViewOriginalInset = _scrollView.mj_inset;
        
        // 添加监听
        [self addObservers];

Copy link
Collaborator

@wolfcon wolfcon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为了统一写法易于理解.

self.mj_x = -_scrollView.mj_insetL;
改为
self.mj_x = -newSuperview.mj_insetL;
而不是移动位置.

@wolfcon wolfcon added the bug label May 24, 2019
@wanshanhu79
Copy link
Contributor Author

为了统一写法易于理解.

self.mj_x = -_scrollView.mj_insetL;
改为
self.mj_x = -newSuperview.mj_insetL;
而不是移动位置.

这样做确实更好。

@wolfcon wolfcon merged commit d15fd86 into CoderMJLee:master May 27, 2019
dklinzh added a commit to dklinzh/MJRefresh that referenced this pull request Jun 4, 2019
* master:
  修改在scrollview有偏移量时刷新内容位置不正确的问题 (CoderMJLee#1293)
  暴露 LoadingView 给外部 (CoderMJLee#1288)
  Added ru/uk localization. Small fix on en localization (CoderMJLee#1045)
  Specify platform version greater than or equal to iOS 8.0 (CoderMJLee#1287)
  带动画的刷新完成回调 (CoderMJLee#698)
  - 不通过停止刷新方案解决顶部栏 bug (停止刷新逻辑在切换 Window 时不做控制) (CoderMJLee#1283)
  fix typo (CoderMJLee#1286)
  add travis ci (CoderMJLee#1284)
  Fix CoderMJLee#1279 (CoderMJLee#1281)
  与 3.1.17 相同, 版本号遵循SemVer
  Delete unused method in UIScrollView+MJRefresh (CoderMJLee#1269)
  更新 pods
  修复切换tab栏时,header没有重置位置的bug (CoderMJLee#1271)
  fix example problem: view layout mistake in new iPhone
  add blank space after : (Korean)
  Korean Language (CoderMJLee#1124)
  添加配置类, 用于修改默认配置, 暂时只加了语言选项 (CoderMJLee#1232)
  Update README.md
  修复自动刷新控件  AutoFooter及其子类   设置忽略距离 ignoredScrollViewContentInsetBottom 无效的问题

# Conflicts:
#	MJRefresh/Base/MJRefreshComponent.h
#	MJRefresh/Base/MJRefreshHeader.m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants