Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude scroll indicators while enumerating subviews of a UIScrollView?

I'm trying to adjust my subviews in a UIScrollView subclass, but I don't want to disturb the scroll indicators. There doesn't seem to be any public interface to access these and I want to check if a view is one of the scroll indicators or not (so that I can ignore it).

UIScrollView.h declares these two iVars:

UIImageView* _verticalScrollIndicator;
UIImageView* _horizontalScrollIndicator;

...but I tried the following and got a linker error:

for(UIView* v in self.subviews)
{
    // Ignore the scroll-indicator views
    if( (v == _horizontalScrollIndicator) ||
        (v == _verticalScrollIndicator))
    {
        continue;
    }
    // View is one of mine - do stuff to it...
}

Apple obviously don't want you messing with these, in which case they should do something clever so that the array returned from subviews doesn't include them (come on Apple, it's not that hard!), but until then how can I ignore them?

like image 364
jhabbott Avatar asked Jun 10 '12 01:06

jhabbott


People also ask

What is scroll view in iOS?

Scroll View is used for displaying content more than the size of the screen. It can contain all of the other UI elements like image views, labels, text views and even another scroll view itself.

How does UIScrollView work?

Overview. UIScrollView is the superclass of several UIKit classes, including UITableView and UITextView . A scroll view is a view with an origin that's adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the app's main window.


1 Answers

This ended up being my work-around

BOOL showsVerticalScrollIndicator = self.showsVerticalScrollIndicator;
BOOL showsHorizontalScrollIndicator = self.showsHorizontalScrollIndicator;

self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;

// loop through self.subviews here

self.showsVerticalScrollIndicator = showsVerticalScrollIndicator;
self.showsHorizontalScrollIndicator = showsHorizontalScrollIndicator;
like image 197
clayzar Avatar answered Nov 15 '22 17:11

clayzar