2

I've created main scroll view for scrolling between pages on the screen.

It's dark gray area named scroll 1. Next, on this main scroll I've added small scroll 2(light gray area).

enter image description here

Currently, for scroll 2 I can touch and scroll only if touch located at above scroll 1 area. Please check this:

enter image description here

Scroll 2 added at position:

CGRectMake(25, -40, 250, 85)]

So, it's half outside of frame of scroll 1.

I've set:

scroll1.clipsToBounds = NO;

But it's like clipping touches too.. I need to be able to touch scroll 2 even if it's outside of scroll 2. How this problem can be solved?

Also, main thing I need is that when I'm scrolling small scroll 2 - scroll 1 should not catch touches.

KAMIKAZE
  • 420
  • 6
  • 27

1 Answers1

0

clipsToBounds only covers rendering not touch handling - it will allow your view to be drawn outside the bounds but it does not extend the touch handling.

The easiest way to achieve what you want here is to have a container view that is big enough to hold both scroll views and then add the scroll views to this container instead of adding the small scroll view to the big one.

Paul.s
  • 38,494
  • 5
  • 70
  • 88
  • As I wrote at the last lines of my question: "Also, main thing I need is that when I'm scrolling small scroll 2 - scroll 1 should not catch touches." So I can't change container frame. Also later scroll 2 will be move outside from the scroll 1. – KAMIKAZE Mar 19 '17 at 14:59
  • The large scrollview will not capture the small scrollview's touches if the small scrollview is added in front of the large scrollview. – Paul.s Mar 19 '17 at 17:03
  • Yes, but at the same time small scroll not working if it's added(as reminder it's a child of big scroll) at position for example: (x:0, y: -100). That's what I'm showing on my gif image. I can scroll small when I touch it at above big scroll area, but when I touch outside big scroll(parent of small scroll), it's not scrolling. That's the problem. – KAMIKAZE Mar 19 '17 at 17:50
  • Touch handling is only within the parents bounds. If you add a view so parts of it are outside the parents bounds then those areas will not receive touches. Hence why I'm saying you should change your hierarchy. – Paul.s Mar 19 '17 at 18:32
  • I've told you how you solve the problem - restructure your hierarchy, do not add the small scrollView to the large one. They should both have a common superview that is large enough to hold both of them. You can hack it to work by messing with hit testing but you are going against the tide and should probably just rethink your architecture to do it properly. – Paul.s Mar 19 '17 at 22:40
  • Actually, I've found probably same question http://stackoverflow.com/questions/7848960/detecting-clicks-outside-of-uiscrollview but it's not working for my case.. Basically, I just need to able to scroll big scroll 1 in the center area of the screen, with smaller scroll added on it, and at the same time able to scroll small scroll 2 without moving it's parent, scroll 1. – KAMIKAZE Mar 20 '17 at 10:51