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

加载数据源不足以让tableView充满整个屏幕的时候,点击菜单按钮头部下坠为初始高度问题 #1

Open
Mryawn opened this issue Aug 7, 2017 · 19 comments

Comments

@Mryawn
Copy link

Mryawn commented Aug 7, 2017

加载数据源不足以让tableView充满整个屏幕的时候,点击菜单按钮头部下坠为初始高度,而不是上滑的高度。请问有什么好的方式可以处理吗?

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017 via email

@Mryawn
Copy link
Author

Mryawn commented Aug 7, 2017

请问有什么办法可以解决这个问题吗?目前准备用您的这个Demo实现公司项目要求,其他都满足了,但产品不能接受头部自动回落的效果。我在tableView初始化及刷新的地方重设contentsize,contentOffset都没有效果

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017 via email

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

// 本类中的scrollView的代理方法(目前本类只有一个self.scrollView)

  • (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView == self.scrollView) {
    // 将当前控制器的view带到最前面去,这是为了防止下一个控制器的view挡住了头部
    BaseViewController baseVc = self.childViewControllers[_selectedIndex];
    if ([baseVc isViewLoaded]) {
    [self.scrollView bringSubviewToFront:baseVc.view];
    }
    // 横向切换tableView时头部不要跟随tableView偏移
    CGRect headerFrame = self.headerView.frame;
    headerFrame.origin.x = scrollView.contentOffset.x-kScreenW
    _selectedIndex;
    self.headerView.frame = headerFrame;

      [self configerHeaderY];
      
      // 如果scrollView的内容很少,在屏幕范围内,则自动回落
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
          if (baseVc.scrollView.contentSize.height < kScreenH && [baseVc isViewLoaded]) {
              [baseVc.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
          }
      });
    

    }

}
我的3个demo只有爱奇艺做了自动回落的处理,你在爱奇艺的 demo中找到以上那歌方法,然后删除 dispatch_after那个地方就可以了

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

爱奇艺的效果逻辑挺复杂的,尽管我写了很多注释,但我也是怕自己日后忘记,别人未必看得懂我注释的意思

@Mryawn
Copy link
Author

Mryawn commented Aug 7, 2017

您好,我试了您说的爱奇艺方法,注释掉了确实没有问题了。不过我这边产品要求要在菜单栏下面进行刷新,所以选择的您的仿美团来做。里面好像没有这个逻辑在。另外,如果把BaseViewController里面viewDidLoad中rowCount设置为小于一屏显示数量。点击第二个菜单栏button,然后在切换到第一个,上拉加载更过数据,滑动到最上部。再次切换回第二个。头部不会回落但会将上拉刷新的view带出来。

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

我待会儿去把这个问题解决掉,问题已经发现了,我现在有点忙

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

美团要比爱奇艺简单很多

@Mryawn
Copy link
Author

Mryawn commented Aug 7, 2017

好的,太感谢了!

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

写好了,但是我不想以此需求更新到github,因为我想很少有公司会这样去需求,既然tablView充不满,那自然得回落,假如不回落,那么剩余的 tableView空白的部分展示出来干嘛,这也不符合scrollView的弹性效果,我观察了微博,美团这些大型app,都是必须回落的,而且不回落也很难看,吊在那里。
反正我也按你的公司需求改了一下,你看看有没有问题,看看我以什么方式发给你比较好,github我不更新此需求。
另外我加了一个功能,假如正在刷新,我不允许滑动scrollView左右切换,这也是刚刚观察其余app发现的

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

其实有很多app都是不管何时都直接隐藏上拉加载的控件的,你也可以直接隐藏。

@Mryawn
Copy link
Author

Mryawn commented Aug 7, 2017

那麻烦您发下我QQ邮箱吧,377185062@qq.com。还有一个不情之请,可以麻烦您把跟改的地方标注下吗?我想学习下。 万分感谢,您帮了我的大忙了!

@SPStore
Copy link
Owner

SPStore commented Aug 7, 2017

你关闭了数字邮箱

@Mryawn
Copy link
Author

Mryawn commented Aug 7, 2017

您好,实在不好意思。什么时候关的都不知道了。现在可以了

@SPStore
Copy link
Owner

SPStore commented Aug 8, 2017

好了

@Mryawn
Copy link
Author

Mryawn commented Aug 8, 2017

好的,已经收到。非常感谢!

@awesomedu
Copy link

写得非常好,请问作者,点击切换使tableView 不回落,应该怎么改了?

@BichKhun
Copy link

BichKhun commented Jul 27, 2018

请问作者,仿美团那里,如果当前页面隐藏导航栏或者其他页面隐藏了导航栏,先把头部视图上滑到隐藏了,在进行跳转回来后会导致头部视图掉下来,这个怎么解决

@mlp1995
Copy link

mlp1995 commented Mar 27, 2019

怎么改的啊 我们公司也有这个需求..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants