简体   繁体   English

UITableView滚动指示器不会隐藏在顶部或底部

[英]UITableView scroll indicator won't hide at top or bottom

I have a problem with UITableView. 我有UITableView的问题。 It won't hide the scroll indicator after: 它之后不会隐藏滚动指示器:

1) scrolling fast 1)快速滚动

2) and then hitting the top or bottom of the table. 2)然后击中桌子的顶部或底部。

Here's a screenshot. 这是一个截图。

连续显示滚动条的屏幕截图

How can I make sure the scroll indicator hides correctly as expected? 如何确保滚动指示器按预期正确隐藏?

Please note that bouncing is off. 请注意,弹跳已关闭。 I also don't want to just hide the scroll indicator, I just want it to disappear as expected when scrolling stops at the top or the bottom. 我也不想隐藏滚动指示器,我只是希望它在滚动停止在顶部或底部时按预期消失。

EDIT: This problem seems to be caused by setting the view controller setting automaticallyAdjustsScrollViewInsets to false . 编辑:这个问题似乎是由于将视图控制器设置automaticallyAdjustsScrollViewInsets设置为automaticallyAdjustsScrollViewInsetsfalse It seems that the following 3 things need to be set to reproduce the problem: 似乎需要设置以下3件事来重现问题:

1) the table view bounces needs to be off 1)表视图弹跳需要关闭

2) the view controller setting automaticallyAdjustsScrollViewInsets to false (This is to fix a different problem where the scroll indicator does not look right at all) 2)视图控制器automaticallyAdjustsScrollViewInsets设置调整automaticallyAdjustsScrollViewInsetsfalse (这是为了解决滚动指示器看起来不正确的另一个问题)

3) The view of the UIViewController itself should not be the table view, the table view has to be a subview. 3)UIViewController本身的视图不应该是表视图,表视图必须是子视图。

In viewDidLoad that will look something like this: viewDidLoad ,它看起来像这样:

self.view_table = [[UITableView alloc] initWithFrame:self.view.frame];
self.view_table.bounces = false;
self.automaticallyAdjustsScrollViewInsets = false;

Also, the content of the table view needs to be bigger than the height of its frame. 此外,表格视图的内容需要大于其框架的高度。

UITableView inherits from UIScrollView, so you'll need to use UIScrollView's properties: UITableView继承自UIScrollView,因此您需要使用UIScrollView的属性:

Property: showsVerticalScrollIndicator
A Boolean value that controls whether the vertical scroll indicator is visible.

Take a look at the documentation . 看一下文档

Try this : 尝试这个 :

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    if (!scrollView.bounces) {
        targetContentOffset->y = -1;//Scrollbar does not move here, because bounces is disabled, but scrollbar can hidden.
    }
}

Do the Follwoing steps. 做Follwoing步骤。

  1. Go to XIB 转到XIB
  2. select the Respective table 选择各自的表格
  3. Go to Properties and Disable the Horizontal and Vertical Scrollers. 转到属性并禁用水平和垂直滚动条。

I have an answer based on the answer by 范亚楠. 根据范亚楠的回答,我得到了答案。

In the UITableViewDelegate : Objective-C : UITableViewDelegateObjective-C

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    if (!scrollView.bounces) {
        if(targetContentOffset->y <= 1)
        {
            targetContentOffset->y = 0.01;
        }
        else if(targetContentOffset->y >= scrollView.contentSize.height - scrollView.height)
        {
            targetContentOffset->y = scrollView.contentSize.height - scrollView.height - 0.01;
        }
    }
}

Swift 4: 斯威夫特4:

func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
    guard !scrollView.bounces else {
        return
    }

    if(targetContentOffset.pointee.y <= 1)
    {
        targetContentOffset.pointee.y = 0.01;
    }
    else if(targetContentOffset.pointee.y >= scrollView.contentSize.height - scrollView.height)
    {
        targetContentOffset.pointee.y = scrollView.contentSize.height - scrollView.height - 0.01;
    }
}

If the table view is scrolling to the top or the bottom this code makes it stop very close but not quite at the end. 如果表视图滚动到顶部或底部,则此代码使其停止非常接近但不完全结束。 This allows the scroll indicator to disappear. 这允许滚动指示器消失。

In viewwillLoad() Make tableView.showsVerticalScrollIndicator = false 在viewwillLoad()中,使tableView.showsVerticalScrollIndicator = false

to disable the scroll indicators in the scroll action view in the tableView 禁用tableView中滚动操作视图中的滚动指示器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM