【问题标题】:Removing the white space between UITableView and UIRefreshControl when dragging拖动时删除 UITableView 和 UIRefreshControl 之间的空白
【发布时间】:2015-01-29 07:56:06
【问题描述】:

我有一个带有 UIRefreshControl 的表格视图。

表格的第一行是蓝色,UIRefreshControl 背景颜色也是蓝色。

当我向下拖动表格以刷新它时,我看到一条白线将表格和 UIRefreshControl 分开。

当我停止拖动表格时,这条线消失了。

如何在不更改白色的 tableview 背景颜色的情况下删除这条白线?

附上图片以供澄清:

【问题讨论】:

标签: ios xcode swift


【解决方案1】:

与Jing的回答类似,我做了一个gap-cover view,并在刷新控件后面介绍了它。我不需要做任何滚动时间调整,因为负 y 位置就足够了。

let gapCoverView = UIView(frame: CGRect(x: 0, y: -200, width: self.view.frame.width, height: 250))
gapCoverView.backgroundColor = UIColor.red
self.view.insertSubview(gapCoverView, belowSubview: refreshControl!)

【讨论】:

    【解决方案2】:

    我有办法解决这个问题。如果您不想更改表格视图的背景颜色并且仍想删除此空间。

    基本上在UIRefreshControl后面创建一个UIView *view,并在viewDidLoad方法中设置view的背景颜色为你想要的颜色

    -(void)viewDidLoad
    {
        //you implementation of viewDidLoad
        self.view = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,0)];
        self.view.backgroundColor = [UIColor yourBackgroundColor];
        [self.tableView insertSubview:self.view belowSubview:self.refreshControl];
    }
    

    然后实现一个UIScrollViewDelegate的方法,动态改变UIRefreshControl后面的view的高度来掩盖这个空隙。

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        CGFloat offset = scrollView.contentOffset.y;
        [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, offset + 20)]; // or any small number
    }
    

    请注意,您可能仍会看到一条线,因为它是 tableview 的分隔符,您可以更改 tableView 的分隔符颜色或样式以将其删除。

    【讨论】:

      【解决方案3】:

      我最近也遇到了这个问题,在我看来这可能是UIRefreshControl 中的一个错误。我发布了我认为正在发生的事情here

      【讨论】: