have scroll view bounce between 2 views

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

  1. straber macrumors member

    Joined:
    Jul 3, 2012
    #1
    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:

    Code:
    - (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?

    Thanks!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    UIScrollViews have a paging mechanism. Look into it.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

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

Share This Page