0

EDIT: Thanks to everyone who tried to help, I was trying to reuse two UIScrollViews to save some time. But it appears the UIScrollView approach won't save me any time, so I'm coding the view entirely by hand.

I've got two UIScrollView's, one who can only scroll horizontally and one vertically, who overlap at a part of the screen.

   -----
   |   |
   |   |
   |   |
   |   |
|--+---+----------|
|  | A |          |
|--+---+----------|
   |   |
   |   |
   -----

I'd like one scrollview to handle the horizontal swipe gestures in area 'A', and the other the vertical ones, but I can't seem to get this to work.

Anyone having any idea on how to approach this?

Pieter
  • 17,435
  • 8
  • 50
  • 89
  • I think the view on the top will always swallow the event, but you can try send the touch event by yourself from the top view to the other one if it's vertical – Mark E Jun 14 '13 at 14:48
  • @MarkE yes I know, I tried to detect 'vertical' or 'horizontal' movement in `hitTest` of a parent view and `bringSubviewToFront` based on that, but I can't get it to work properly – Pieter Jun 14 '13 at 14:51
  • don't use `bringSubviewToFront` use, `[scrollView setContentOffset:CGPointMake(x, y) animated:NO];` to move the other view while reading the touch data on the view in the front – Mark E Jun 14 '13 at 15:04
  • @MarkE I don't see how that's supposed to work, the upper view shouldn't scroll in the direction of the lower view (and vice versa), added an ASCII drawing to try to clarify what I mean – Pieter Jun 14 '13 at 15:20
  • The easiest way in my mind would be to setup a view on top of them both that consumes all touch events (or just ones with motion) and then tells the respective scroll view that your touch moved so much in the x direction and so much in the y direction. – Putz1103 Jun 14 '13 at 15:27
  • @Putz1103 I tried adding a view on top to pass events, but since you only know when `touchesMoved` happens who needs to get the `touchesBegan` I can't quite get that to work that as it should. – Pieter Jun 15 '13 at 08:20
  • You are going to have to handle all touch events in the overlay view (began, moved, ended, canceled). Then when it's just a tap you will have to programatically touch whatever you need to. – Putz1103 Jun 15 '13 at 14:34
  • @Pieter did you manage to find a solution to that? I'm experiencing similar issue... – goldengil Apr 02 '14 at 13:13
  • @goldengil no, I wrote a custom UIView, not using any UIScrollViews at all – Pieter Apr 02 '14 at 13:14
  • @Pieter Well, I just found the answer in some other post. I'll link it here: [link](http://stackoverflow.com/a/7918717/1868924) so if someone else is getting stuck on the same issue, they won't waste to much of their time. :) i'll add it as an answer – goldengil Apr 02 '14 at 14:36

2 Answers2

1

Would handling touchesBegan, touchesMoved and touchesEnded in the scroll view that is getting the touch events and manually calling them on the other scroll view work?

You could also scroll the other scroll view by handling the scroll view delegate in the scroll view getting the touches.

jjxtra
  • 20,415
  • 16
  • 100
  • 140
0

I had similar issue. Had 2 UIScrollView that overlapped each other completely, and needed to scroll one of them as a result of scrolling the other.

After searching for a while I found similar post over here:

Did the job for me :)

Community
  • 1
  • 1
goldengil
  • 1,007
  • 9
  • 25
  • That's a different issue, two scrollviews matching each other; while my problem is getting them to move independently but each in a separate direction. But since you ended up here with your problem, others with a similar problem could too I suppose, so it might be helpful to them :) – Pieter Apr 02 '14 at 14:45
  • Well, that could be a good start. The only thing left to do is to calculate the ratio between the movement of the first and the size of the second (comparing to the size of the first). Yet, you already solve your issue (according to your comment in the question), so it might indeed help someone :) – goldengil Apr 02 '14 at 14:49