开发者

UIScrollView not showing scroll indicator

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

开发者_StackOverflow社区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?


Had the same problem and couldn't find the cause. The last answer gave the final hint: whenever I added new subviews I first removed all existing subviews from the scrollview (and apparently also the scroll indicators).

After checking in my loop, if the subview really was of the kind I wanted to be removed the scroll indicators showed up:

for (NSObject * subview in [[[scrollView subviews] copy] autorelease]) {
    if ([subview isKindOfClass:[MySubView class]]) {
       [(MySubView*)subview removeFromSuperview];
    }
}   

Update: changed code to Nikolai's suggestion


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];


For me, the horizontal indicator had mysteriously disappeared in my app on iOS 7. Later found out that for some strange reason, I had to enable both Shows Horizontal Indicator and Shows Vertical Indicator to make the horizontal one show up. If I set it to not show the vertical indicator, it would also not show horizontal indicator.

UIScrollView not showing scroll indicator


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

self.showsVerticalScrollIndicator = NO;
self.showsVerticalScrollIndicator = YES;


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.


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.


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):

UIScrollView not showing scroll indicator


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜