Displays the scroll bar of UIScrollView.
I checked the UIScrollView methods and attributes and found that there is no corresponding method. Only one flashScrollIndicators is relatively reliable, but it only shows the scroll bar for a short time and then disappears automatically. I can't start a timer. I keep refreshing this method.
Search on stackoverflow and the Final Solution points to this page.
Paste the source code as follows:
1. # define noDisableVerticalScrollTag 836913
2. # define noDisableHorizontalScrollTag 836914
3.
4. @ implementation UIImageView (ForScrollView)
5.
6.-(void) setAlpha :( float) alpha {
7.
8. if (self. superview. tag = noDisableVerticalScrollTag ){
9. if (alpha = 0 & self. autoresizingMask = UIViewAutoresizingFlexibleLeftMargin ){
10. if (self. frame. size. width <10 & self. frame. size. height> self. frame. size. width ){
11. UIScrollView * SC = (UIScrollView *) self. superview;
12. if (SC. frame. size. height <SC. contentSize. height ){
13. return;
14 .}
15 .}
16 .}
17 .}
18.
19. if (self. superview. tag = noDisableHorizontalScrollTag ){
20. if (alpha = 0 & self. autoresizingMask = UIViewAutoresizingFlexibleTopMargin ){
21. if (self. frame. size. height <10 & self. frame. size. height <self. frame. size. width ){
22. UIScrollView * SC = (UIScrollView *) self. superview;
23. if (SC. frame. size. width <SC. contentSize. width ){
24. return;
25 .}
26 .}
27 .}
28 .}
29.
30. [super setAlpha: alpha];
31 .}
32. @ end
Summarize the principles of this method:
1) the scroll bar of UIScrollView is UIImageView.
2) After the UIScrollView is flashScrollIndicators, its scroll bar will be called by setAlpha.
3) because it is implemented through the Category of UIImageView, the impact on UIImageView is global. Therefore, this method sets the UIScrollView tag to determine whether the current UIImageView is affected or not.
4) if you want to keep the horizontal scroll bar, you only need to set the UIScrollView tag to the noDisableVerticalScrollTag in the code, and then call flashScrollIndicators. You do not need to manually call the setAlpha code, for the reason, see the second point.
This is an online reference solution. You can modify it as needed.