Can touch events be forwarded to an MKMapView?

Gruntcakes

I want to display a map view as a permanent background while other views are displayed on top of it (I'm going to set the alpha of the top view to something like 0.9 so the map is just faintly visible underneath) and at some points the map get revealed.

I have a container view which is layered on top of the map view and I would like to know if touch events that occur within the bounds of the container view can be passed to the map view so that it can be scrolled etc. Here's a sketch project showing an example of the architecture.enter image description here

enter image description here

(The Container view is on top of the bottom half of the map view, the container view and contained View Controller's view's alphas are both 0, so to the user the map is visible on the entire screen).

Its easy to forward the touch events occurring within the Contained View Controller's views or child view controllers to the Map Background View Controller.

If I do something like pass the touch event to the map view like this

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    MapBackgroundViewController *parent = (MapBackgroundViewController *) self.parentViewController;
    [parent.mapView touchesBegan:touches withEvent:event];
}

then nothing happens.

Is there a way of passing the touch events to the map view such that it will scroll etc.?

Timothy Moose

Yes, you can do this.

What I do is subclass UIView and override hitTest:withEvent: such that touches are passed through unless a subview is touched. Something like this:

@implementation PassthroughView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *view = [super hitTest:point withEvent:event];
    return view == self ? nil : view;
}

@end

Then I assign this class to my container view and the contained view controller's main view in IB. So you can still interact with the content of the contained view controller, but touches on the container itself get passed through to the map.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Prevent touch events on MKMapView being detected when a MKAnnotation is tapped

From Dev

Disable touch events while MKMapview is doing SetRegion Animated function call

From Dev

Is there a container that can handle touch events in Xamarin

From Dev

How and can I disable touch events in Javascript?

From Dev

Calabash - can't test touch events

From Dev

MKMapView to deny single touch panning

From Dev

Can't receive touch events from UIButtons placed ontop of GMSMapView

From Dev

I can't seem to recognize touch events on android

From Dev

How can I make touch events pass through a UIView (similar to pointer-events:none in CSS)?

From Dev

touch events firing twice

From Dev

SKSpriteNode not detecting touch events

From Dev

Safari not firing touch events

From Dev

Overlapping Fragments and Touch Events

From Dev

Switch to touch events with SnapSvg

From Dev

Processing Touch and Gesture Events

From Dev

Polymer project, touch events

From Dev

Click events in Sencha touch

From Dev

Enable Touch Events Chrome

From Dev

Touch events not working EaselJS

From Dev

jQuery touch events

From Dev

Can `auto &&` parameters be perfect forwarded?

From Dev

Can the forwarded Kerberos ticket be renewed?

From Dev

touch left / touch right events in reagent

From Dev

How can a forwarded email know the forwarded-to email address?

From Dev

How to eliminate pointer events, but not touch events?

From Dev

How can I reliably simulate touch events on Android without root (like Automate and Tasker)?

From Dev

Drawerlayout is intercepting all touch events

From Dev

Handling touch events to one UITableCell

From Dev

Handling Hover Events on a Touch Screen

Related Related

HotTag

Archive