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

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.

enter image description here

查看更多
劳资没心,怎么记你
3楼-- · 2019-02-01 08:00

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

查看更多
登录 后发表回答