How to keep the UIScrollView scroll bar indicator displayed

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.