0
votes

UIScrollView has several UILabel subviews, which are set to scroll horizontally (think about Instagram filters scrolling view). I can scroll UIScrollSubview, act upon tapping on a UILabel subview. Next thing I would like to achieve is to programmatically scroll to an invisible UILabel subview, when the users selects the last visible subview on the right (similar to how the instagram filters scroll out of the visible area when the user selects the last visible filter).

When the user touches the last visible UILabel subview, I execute

[_scrollView setContentOffset:CGPointMake(64, 0) animated:YES];

where 64 is the width of every UILabel subview of the scrollView.

This works fine only on the first selection event of the last visible subview. Once the scrollView scrolled to reveal the desired subview on the right side of the selected one, and I select newly revealed subview, the scrollView correctly scrolls to the left revealing the next invisible subview, but then jumps back (to the right) two positions (128). The desired behaviour is to always scroll to the left when the last visible subview on the right is selected (right now this happens only on the first selection).

Any suggestions would be appreciated.

Thanks.

EDIT: The bouncing issue went away in 2 cases:

  1. scrollView.pagingEnabled: NO;

  2. user performs relatively long touches on subviews

1

1 Answers

0
votes

You should add 64 to the current contentOffset.

[_scrollView setContentOffset:CGPointMake(_scrollView.contentOffset.x + 64, 0) animated:YES];