Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on a page, one that only scrolls horizontally, one that only scrolls vertically, and one that scrolls both horizontally and vertically. I want to lock the views together, so that the horizontal location of the horizontal only scrollview matches the horizontal location of the main scrollview, and the vertical scrollview likewise, so that dragging the main scrollview around controls the horizontal and vertical scrollviews.
Problem is, I'm completely stumped. I've looked around inside the apple documentation, but there doesn't seem to be any way to do this officially. One thought that I had was to somehow "clone" any touch on any of the scrollviews to a point on the other two, but I have no idea how to do this. If anyone has any thoughts on this, I'd very much appreciate it.
Edit: I tried the suggestion of subclassing UIScrollView and overriding touchesMoved to call touchesMoved on the other scroll views. Unfortunately, touchesMoved doesn't get called for scrolling motions as UIScrollView intercepts those motions somehow and uses them to control its scrolling. I started looking around more low level stuff and found the core animation scroll layers, but ideally I wouldn't want to recreate UIScrollView from scratch. Still trying to figure this one out.
I think the simplest way would be to add a delegate to your scrollviews which implement the following method:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Then you can check the contentOffset to check by how much the scrollview did actually scroll, and update the main scrollview accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With