2
votes

I have two scrollViews i.e one inside other, -OuterScroll ----InnerScroll

Need Outer scrollView to stop automatically and inner starts in a single scroll when outer ScrollView reaches contentOffSet value of greater than 300.

So far..

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView)
    {

        if (scrollView.contentOffset.y>300) {
            [scrollContentView setScrollEnabled:YES];
        }else if (scrollView.contentOffset.y<10){
            [scrollContentView setScrollEnabled:NO];
        }

     }
 }

By the way scrollSuperView is outerScroll and scrollContentView is inner. Any help appreciated.

1.scrollSuperView (Outer) frame = CGRect(0, 0, 320, 468) contentSize = CGSizeMake(320, 600)

2.scrollContentView (Inner) frame = CGRect(0, 300, 320, 468) contentSize = CGSizeMake(320, 600)

So i have above two scrollViews as mentioned outer and inner Once outer scrollView reaches content offset of >300 then scrollEvent much be passed to inner ScrollView if user is scrolling by putting finger on inner ScrollView..

Hope its more clear now.

2
is this code not working?.sathiamoorthy
have you found the solution?Vashum
I am sorry @Vashum its very old post i don't remember what i did at that time.Pankaj Wadhwa

2 Answers

0
votes

Setting outer scrollView's delaysContentTouches to NO will pass touch events from outer scrollView to inner scrollView... "in a single move"

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == scrollSuperView) {
        //outer scrollView
        if (scrollView.contentOffset.y >= 300) {
            //NSLog(@"Outer scrollView ContentOffset has reached 300");
            [scrollSuperView setDelaysContentTouches:NO];
            [scrollContentView setScrollEnabled:YES];
        }
    }
    else if (scrollView == scrollContentView) {
        //inner scrollView
        if (scrollView.contentOffset.y == 0) {
            //NSLog(@"Inner scrollView ContentOffset has reached 0");
            [scrollSuperView setDelaysContentTouches:YES];
            [scrollContentView setScrollEnabled:NO];
        }
    }
}

Assumptions:

  1. scrollSuperView (Outer)
    • frame = CGRect(0, 0, 320, 300)
    • contentSize = CGSizeMake(320, 600)
    • delaysContentTouches = YES
    • scrollEnabled = YES
  2. scrollContentView (Inner)
    • frame = CGRect(0, 400, 320, 200)
    • contentSize = CGSizeMake(320, 400)
    • delaysContentTouches = YES
    • scrollEnabled = NO
0
votes
-(void)viewDidLoad{
 //write your code here
 innerScrollView.scrollEnabled =NO;
 outerScrollView.scrollEnabled =YES;
 //above two lines makes touch(scroll) events given to outer and not inner.
}

And your modified method,

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView)
    {

        if (scrollView.contentOffset.y>300) {
            outerScrollView.scrollEnabled =NO;
            innerScrollView.scrollEnabled =YES;
            [outerScrollView setContentOffset:CGPointMake(0, 200)];
     }
 }
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    [self.view endEditing:YES];
    if (scrollView ==scrollSuperView && decelerate==NO)
    {

        if (scrollView.contentOffset.y>300) {
            outerScrollView.scrollEnabled =NO;
            innerScrollView.scrollEnabled =YES;
            [outerScrollView setContentOffset:CGPointMake(0, 200) animated:YES];
     }
 }
}