UIScrollView not showing scroll indicator

2019-02-01 07:02发布

I have a UIScrollView which I create and size dynamically using...

scrollView.contentSize = CGSizeMake(scrollView.frame.size.width , length);

I then add subviews to the UIScrollView. I do have scrollView.showsVerticalScrollIndicator = YES;

When scrolling the scroll indicator never appears.

Even if I call [scrollView flashScrollIndicators] nothing happens.

Ideas?

8条回答
闹够了就滚
2楼-- · 2019-02-01 07:42

Two conditions,

  1. If you are using a storyboard
  2. If you are using a UITableView inside a UIViewController

Then, you should check your indicator insets are set to 0 (or any other number that is relevant to your autolayout):

enter image description here

查看更多
【Aperson】
3楼-- · 2019-02-01 07:43

When I've dealt with this before, in my implementation of a grid, I would occasionally get some cells over the top of the scroll indicator. To fix this I am now inserting subviews at index 0 rather than adding them, which adds them to the top. So try something like this:

[scrollview insertSubview:subview atIndex:0];

查看更多
别忘想泡老子
4楼-- · 2019-02-01 07:43

Noticed this when the UIScrollView was a 48 px tall horizontal band, scrollable horizontally. Maybe Cocoa decides the area is too small for a scroll indicator...

查看更多
叼着烟拽天下
5楼-- · 2019-02-01 07:45

It can happen also if the parent of the scrollview is smaller horizontally than the scroll view itself :

The scroll bar is stuck to the right side of the ScrollView / TableView and this right side is not visible due to the parent bounds ( with a clipToBounds hidding it for instance).

I've seen this issue so I share it in case it can help.

Just check the width of your ScrollView's frame not to be bigger than the width of its parent view frame.

查看更多
对你真心纯属浪费
6楼-- · 2019-02-01 07:50

I fix this by adding this code after add new subview:

self.showsVerticalScrollIndicator = NO;
self.showsVerticalScrollIndicator = YES;
查看更多
Emotional °昔
7楼-- · 2019-02-01 07:53

It will also happen (at least in the case of a UITableView) if the contentSize is too small for the table view to scroll. If you have enabled bouncing, then the tableview does not actually scroll and does not display the indicators therefore. Try fitting more content inside.

查看更多
登录 后发表回答