views:

307

answers:

1

Hello all,

Doing some iPhone dev, have the app working quite well. However, I have a UIScrollView with autoresizing content and contentSize which works quite well, except when I rotate to the landscape view it always has an extra 100 or so pixels on the scroll height. I don' want users to be able to scroll so far past the content.

Has anyone else had this issue or know of a fix?

thanks in advance,

Michael

+3  A: 

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
}
zath