I built a project that has a mapView
(Google Maps), tableView and a UIScrollView
.
The tableView is on the bottom and when the app starts you see a really small part of it and the most of it is out of the screen (on the bottom). When the user scrolls the tableView
is revealed and going up from the bottom until it covers all of the screen. It's all working but I have one small problem: I want that the user will be able to touch the map (zoom, move, etc.) but the UIScrollView
is on top of the map and when the user tries to interact with the map the scrollView detects a scroll and the map doesn't get a touch event. Is there any way that the UIScrollView
wouldn't detect the touch on the area of the map? The scrollView
should cover all of the screen for the tableView
detection (or maybe not and there is another way?) and I don't want the map to be a subclass of the scrollView
because it will go up with the table when the user scrolls (I want the tableView
to go on top of the map and not with it).
Thanks!

- 191
- 1
- 13

- 39
- 1
- 5
-
You may need to clarify what it is you're after. You want a tableView to be on top of a mapview, but not receive any touches? – Alex Nov 05 '15 at 20:37
-
The way you are doing things, it is going to be a little complicated. You should make the scrollview start at the bottom of the map, then using auto layout and updating the height constraints, update scrollview's space from the top of the screen when the user scrolls. That way you will be able to touch the map even if there is only 20 pixels showing of it above the scrollview. Also you should post some relevant code and picture to help everyone understand exactly what you are trying to do. – MSU_Bulldog Nov 05 '15 at 21:05
-
@MSU_Bulldog how can I update the height constraints? Maybe you know the name of the function (ObjC) – Yahllilevy Nov 05 '15 at 21:15
-
@Alex I want the user to scroll the table view and tap on the cells – Yahllilevy Nov 05 '15 at 21:15
-
So you want to be able to scroll the tableView up and select cells, but also interact with the map that's under the tableView at the same time? – Alex Nov 05 '15 at 21:19
-
@Alex yes (scroll up and down btw) – Yahllilevy Nov 05 '15 at 21:26
-
Yes you can do that, try googling stuff similar to this post. Basically, you want to forward the touch to another view. http://stackoverflow.com/questions/4585007/receiving-touch-events-on-more-then-one-uiview-simultaneously . Just my 2 cents, your UI sounds a bit cumbersome; maybe make the user scroll away the tableView before interacting with the map again. – Alex Nov 05 '15 at 21:31
-
@Alex Thank you for the advice! I'll try to do that! – Yahllilevy Nov 05 '15 at 21:40
1 Answers
Going off of my comment. You will need to set the top space to superview constraint on the scroll view. Create an IBOutlet for the constraint and a float variable for the value of the constraint and also connect it to your top space to superview constraint that you will create in interface builder on the scrollview.
in your .h:
IBOutlet NSLayoutConstraint *topSpace;
float topSpaceValue;
Then update that constraint using this:
topSpace.constant = topSpaceValue;
You can detect scrolling in the scrollview with this method and set the topSpace constraint:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
topSpace.constant = topSpaceValue;
}
Now, the actual logic of detecting how fast the scrollview is moving and what value to set for topSpaceValue is up to you to figure out. Also you will need to detect what direction the scroll view is moving to increase or decrease the value of topSpaceValue.
This looks like the link you need for detecting the speed: iPhone UIScrollView Speed Check
So according to the speed, set the constraint. And you will probably want to check for a minimum value for the constraint, like 0, so the scrollview doesn't scroll off the top of the screen.

- 1
- 1

- 3,501
- 5
- 37
- 73