0

I have an iphone app where I want to do the following:

  1. A category title bar that is a horizontally scrolling custom paging size UIScrollView where the user can switch between the categories by swiping left or right.
  2. A category content page below the title bar that is also a horizontally scrolling UIScrollView (full screen width paging). The user can also switch between the content pages by swiping left or right.

What I would like to achieve is the following:

  1. Both UIScrollViews are linked together, whereby swiping in the category title bar swipes the content page as well, or swiping in the content page swipes the title bar as well.
  2. If that is not possible, then at the very least, the user must be able to swipe the content page and the title swipes accordingly as well (the reverse is nit necessary).

I do remember seeing some apps implementing something like this, though I can't remember them off my head now. Any ideas how do I go about this?

Thanks!

Sport
  • 8,570
  • 6
  • 46
  • 65
Justin Leo
  • 1,975
  • 3
  • 15
  • 14

2 Answers2

0

i've done it in my app. the category view is like a 'showcase' view, after swipe or touch, trigger a notification. the content can be a UICollectionView, so it has setContentOffset: method to 'goto' dest page. or u can use addChildViewController in contentView, and combine with pagingEnabled UIScrollView.

limboy
  • 3,879
  • 7
  • 37
  • 53
0

With reference to Making two UIScrollViews follow each others scrolling, I did it using by setting the UIScrollView delegate for both scroll views to the parent view controller, and invoked the scrollViewDidScroll method.

- (void)matchScrollView:(UIScrollView *)first toScrollView:(UIScrollView *)second {
    CGPoint offset = first.contentOffset;
    offset.x = (second.contentOffset.x/second.frame.size.width) * first.frame.size.width;
    first.contentOffset = offset;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
     if([scrollView isEqual:firstScrollView]) {
        isSecondScrolling = NO;
    } else if ([scrollView isEqual:secondScrollView]) {
        isSecondScrolling = YES;
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if ([scrollView isEqual:firstScrollView] && isSecondScrolling == NO) {
        [self matchScrollView:secondScrollView toScrollView:firstScrollView];
    } else if ([scrollView isEqual:_midPanelScrollView] && isSecondScrolling == YES) {
        [self matchScrollView:firstScrollView toScrollView:secondScrollView];
    }
}

However I added the boolean isSecondScrolling, to stop the firstScrollView from initiating the matchScrollView when the secondScrollView is scrolling. Otherwise it results in the frame of the secondScrollView being slightly off after each scroll.

Community
  • 1
  • 1
Justin Leo
  • 1,975
  • 3
  • 15
  • 14