D
D
Dmitry Golovanov2018-01-30 12:23:20
iOS
Dmitry Golovanov, 2018-01-30 12:23:20

How to make two UIScrollView dependent on each other?

Good afternoon.
The crux of the problem is this, there are two separate UIScrollViews on the same ViewController.
How to connect them together so that when you move one second one moves identically?
Has anyone else experienced this
? Thank you in advance for your replies!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2018-01-30
@golovanovd

Try like this:

class MultiScrollViewController: UIViewController {
    // ...

    override func viewDidLoad() { 
        super.viewDidLoad()

        firstView.delegate = self
        secondView.delegate = self
    }

    // ...
}

extension MultiScrollViewController: UIScrollViewDelegate {
    func scrollViewDidScroll(scrollView: UIScrollView) {
        firstView.contentOffset = scrollView.contentOffset
        secondView.contentOffset = scrollView.contentOffset
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question