I experienced the same problem. In my case, I was looping through a UIScrollView in an attempt to dynamically calculate it's contentSize. While looping through the subviews, I found two mysterious imageViews amongst the subviews (not added by me), which together added up to exactly 100 pixels. It turns out that these two images are actually the scroll indicator which is automatically added to the scrollview.
My solution was to create a container view class, let's call it ContainerView, and in it I created the scrollview.
Inside of this ContainerView I override the methods addSubview and willRemoveSubview, like this:
- (void)addSubview:(UIView *)view {
[_addedSubviews addObject:view];
[_scrollView addSubview:view];
}
- (void)willRemoveSubview:(UIView *)subview {
[_addedSubviews removeObject:subview];
[_scrollView willRemoveSubview:subview];
}
Now you can add a method for calculating the size. This time we'll loop through the array called _addedSubviews, instead of the scrollviews subviews, because we know that the views inside _addedSubviews are only the ones added by us. And because of this we'll avoid looping through scroll indicators and whatnot :-)
And lastly just loop through and calculate.
- (CGSize)desiredContentSize {
for(UIView *mySubviews in _addedSubviews) {
// Calculate size
}
// Return size
}