3

enter image description here

enter image description here

Just like this, cells can cover MKMapView. When table scrolls down, MKMapView can be touched.

How to? Special thanks

OpenThread
  • 2,096
  • 3
  • 28
  • 49

3 Answers3

3

1.add a header view for table view, 320px height with clear background color.

2.put MKMapView under UITableView.

3.override table view's hitTest:withEvent:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *view = [super hitTest:point withEvent:event];
    if (view == self.tableHeaderView) {
        return nil;
    }
    return view;
}
OpenThread
  • 2,096
  • 3
  • 28
  • 49
  • I tried doing the same. But the map is not visible. The header view is hiding it I feel. – Anil Aug 29 '13 at 09:55
  • @Anil header's background color must be clear, what i forget to say. I think you should know it – OpenThread Sep 03 '13 at 06:00
  • 4
    With the help of this answer I have created a working version of this. For some resusable code and a demo see here https://github.com/danielbowden/DBParallaxMapTableView – Daniel Bowden Oct 10 '13 at 03:44
1

Place your image in background or at least behind your tableview. Then set the size of the first row (or header if you prefer) for something big: maybe 350px. Set the backgroundColor of the tableview to [UIColor clearColor] and set the backgroundColor of your first cell to [UIColor clearColor] too. You may have to take a special care to the opaque property of your views: tableView and the cell

Geraud.ch
  • 1,499
  • 10
  • 15
  • Yes, their position will be all right, but MKMapView cannot get touch events, all events handled by UITableView – OpenThread Oct 22 '12 at 14:48
  • In that case it's quite tricky.You can add the MKMapView on top of your tableview and set a swipe gestureRecognizer on the MKMapView which will change the height of the MKMapView and the origin of the tableView. I won't assure it will work... the mapView does use the swipe gesture and you may have performance issue. At least you should swap your mapView with a screenshot of it when reducing its height http://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically – Geraud.ch Oct 22 '12 at 15:41
  • But change the height of map view, "AutoNavi mark" will go up, in the second screen shot, it doesn't. And in svpply, map view is behind tableview's scroll bar, i think map view should be behind table view – OpenThread Oct 23 '12 at 05:48
  • Ok, so don't change the height of the MapView and just place the tableView on top and forward event from the first tableview cell to the MapKit. But some nasty bugs should come while forwarding touches of any kind... – Geraud.ch Oct 23 '12 at 08:41
  • how to forwarding touches stucks, i overrided touchedMoved:withEvent: of table view, then call[self.nextResponder touchesMoved:withEvent] and [mapview touchesMoved:withEvent:]. But both of them doesn't work – OpenThread Oct 23 '12 at 09:40
0

Here is a Swift 3 version of OpenThread's answer, but it doesn't require you to add a header to your UITableView - just subclass it and add this:

class YourTableView: UITableView {

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        let view = super.hitTest(point, with: event)

        if view is YourTableView {
            return nil
        }

        return view
    }

}
rdougan
  • 7,217
  • 2
  • 34
  • 63