Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

TUIScrollView only responds to contentInset's top value #125

Open
luosheng opened this Issue Oct 21, 2012 · 2 comments

Comments

Projects
None yet
2 participants

It can be reproduced by adding the following line to the ExampleScrollView.m:

_scrollView.contentInset = TUIEdgeInsetsMake(10, 10, 10, 10);

It's supposed to enlarge the scrolling area by 10 points at each edge. However we can only see the extra space at top.

As far as I can tell, the issue lies in the -[TUIScrollView _fixProposedContentOffset:] method... working on it, right now.

This replaced code seems to fix it:

- (CGPoint)_fixProposedContentOffset:(CGPoint)offset {
    CGRect currentBounds = self.bounds;
    CGSize contentSize = _contentSize;

    contentSize.height += _contentInset.top;
    contentSize.width -= _contentInset.left;

    CGFloat mx = offset.x + contentSize.width;
    if(contentSize.width > currentBounds.size.width) {
        if(mx < currentBounds.size.width)
            offset.x = currentBounds.size.width - contentSize.width;

        if(offset.x > 0.0)
            offset.x = _contentInset.right;
    } else {
        offset.x = currentBounds.size.width - contentSize.width;
    }

    CGFloat my = offset.y + contentSize.height;
    if(contentSize.height > currentBounds.size.height) {
        if(my < currentBounds.size.height)
            offset.y = currentBounds.size.height - contentSize.height;

        if(offset.y > 0.0)
            offset.y = _contentInset.bottom;
    } else {
        offset.y = currentBounds.size.height - contentSize.height;
    }

    return offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment