Question

So I have been struggling with this problem for so long now, I believe I have tried every StackOverflow solution available but still I cannot get this right.

I have a "Curtain View" lying on every other view in my social networking application

This is how it looks when the curtain is in default-mode This is how it looks when the curtain is in default-mode

This is how it looks when the curtain is in "down"-mode This is how it looks when the curtain is in "down"-mode

The curtain is a view which is contained in a scroll view.

In order to be able to drag down the curtain, I have had to set the content size to lap over the green buttons, which can be seen in the images.

The content size is something like the black stroked area in this picture below.

enter image description here

My problem. I cannot figure out how I can make my green buttons, "Following, Everybody, Nearby" clickable/touchable when the scrollview is in default-mode. Obviously the content size of the scrollview is lapping over the buttons, but how can i avoid that?

I have experimented with hitTest overriding, tried to pass touch events through the chain of events and
other similar solutions but without luck. I cannot get this to work.

I have implemented the curtain view using a custom view controller containing a scrollview. This view is then added to the root view.

Was it helpful?

Solution

You should hide your UIScrollView when it is in the default position:

scrollView.hidden = YES;

This will prevent the UIScrollView from blocking touches on the buttons beneath it.

See Apple's UIView doco:

A hidden view disappears from its window and does not receive input events. It remains in its superview’s list of subviews, however, and participates in autoresizing as usual.

Then set hidden to NO just before you drag down the curtain.

EDIT:

To answer the questions in your comment:

  1. How would I know if my scroll view is in default position, there is no event triggered? You should be able to determine if your scroll view is in the default (hidden) position or in the down position (showing) by checking the contentOffset property on your scroll view.

  2. Wouldn't the image of the curtain disappear if I set it to hidden? Yes, it would. If you want the view to still be partially showing at the top and not disappear completely, you'll need a different approach (see some suggestions below).

  3. The scroll view is supposed do be 'dragged down' with the finger (of course). So it needs events triggering at all time. You can detect a touch/pan gesture on the main view, and cause the scrollview to move down/up based on that gesture. The gesture doesn't actually need to start inside the scrollview.

Here are some links that I found helpful:

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top