have scroll view bounce between 2 views

Discussion in 'iOS Programming' started by straber, Feb 10, 2013.

  1. straber macrumors member

    Jul 3, 2012
    I want to have 2 views side by side in a scroll view and have the scroll view always scroll one of the views to fully visible so you can never have the scroll view stop with part of one view visible and part of the other visible. I tried doing this with:

    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
        if (scrollView == self.scrollView) {
            CGFloat location = scrollView.contentOffset.x;
            if (location <= self.alarmMenuView.frame.size.width / 2) {
                [UIView animateWithDuration:0.3 animations:^ {
                    [scrollView setContentOffset:CGPointMake(0, 0) animated:NO];
            else {
                [UIView animateWithDuration:0.3 animations:^ {
                    [scrollView setContentOffset:CGPointMake(self.alarmMenuView.frame.size.width, 0) animated:NO];
    but I can still end up in a state where part of each view is visible. How can I make it so only one view is visible at a time?

  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    UIScrollViews have a paging mechanism. Look into it.
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    There is an Apple sample called PhotoScroller that does this for images.

Share This Page