David Skrundz
David Skrundz

Reputation: 13347

UIScrollView 1D Bouncing but 2D Scrolling

The project I'm currently working requires that a UIScrollView to scroll vertically and horizontally, however, it must only bounce vertically. Is this possible? I noticed that there is a verticalBouncing and horizontalBouncing property in the declaration, could that be the answer?

Upvotes: 0

Views: 168

Answers (1)

Bartosz Ciechanowski
Bartosz Ciechanowski

Reputation: 10333

You cannot access @package ivars directly. However, you can register yourself as delegate of UIScrollView and implemenet this code

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float maxX = scrollView.contentSize.width - scrollView.frame.size.width;

    CGPoint offset = scrollView.contentOffset;
    offset.x = MAX(MIN(maxX, offset.x), 0);
    scrollView.contentOffset = offset;
}

Upvotes: 3

Related Questions