Using scrollViewDidScroll with multiple UIScrollViews

I have two horizontally scrolling UIScrollViews arranged vertically one above the other within the same ViewController. Each UIScrollView occupies half the screen. I am trying to track the position of both UIScrollViews myself.

I have successfully used this to track the position of the top UIScrollView:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {

int Position = (scrollView1.contentOffset.x);

    if (Position == 0) {
    NSLog(@"Play A"); 
    }

    else if (Position == 280) {
    NSLog(@"Play B"); 
    }

//etc.
}

I would also like to track the position of the bottom UIScrollView.

When I try to use this:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView2 {

int Position2 = (scrollView2.contentOffset.x);

if (Position2 == 0) {
NSLog(@"Play A2"); 
}

else if (Position == 280) {
NSLog(@"Play B2"); 
}

//etc.
}

I am getting the error "FirstViewConroller scrollViewDidScroll scroll override".

So, having decided to click, I tried a rather hacky solution and tried to use it instead:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView2

{

int Position2 = (scrollView2.contentOffset.x);

if (Position2 == 0) {
NSLog(@"Play A2"); 
}

else if (Position2 == 280) {
NSLog(@"Play B2"); 
}

//etc.
}

, UIScrollViews . , UIScrollView 280 ( ) , , :


PlayB2

UIScrollView , :

PlayC
PlayC2

.

, , . viewDidLoad :

scrollView1.delegate = self;
scrollView2.delegate = self;

, ? , , , scrollViews ? .

- UIScrollView UIScrollView , , - , , .

. , , . . , , -, .

+3
2

, UIScrollView. scrollView1 scrollView2 IB, :

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView1 == scrollView) {
        // Do stuff with scrollView1
    } else if (scrollView2 == scrollView) {
        // Do stuff with scrollView2
    }
}
+14

, scrollviews. , -scrollViewDidScroll: scrollview, , .

.

0

Source: https://habr.com/ru/post/1718626/


All Articles