Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3318702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:44:16+00:00 2026-05-17T22:44:16+00:00

I’m not sure what I am doing wrong but I try to catch touches

  • 0

I’m not sure what I am doing wrong but I try to catch touches on a MKMapView object. I subclassed it by creating the following class :

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@interface MapViewWithTouches : MKMapView {

}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event;   

@end

And the implementation :

#import "MapViewWithTouches.h"
@implementation MapViewWithTouches

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *) event {

    NSLog(@"hello");
    //[super touchesBegan:touches   withEvent:event];

}
@end

But it looks like when I use this class, I see nothing on the Console :

MapViewWithTouches *mapView = [[MapViewWithTouches alloc] initWithFrame:self.view.frame];
[self.view insertSubview:mapView atIndex:0];

Any idea what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:44:16+00:00Added an answer on May 17, 2026 at 10:44 pm

    The best way I have found to achieve this is with a Gesture Recognizer. Other ways turn out to involve a lot of hackish programming that imperfectly duplicates Apple’s code, especially in the case of multitouch.

    Here’s what I do: Implement a gesture recognizer that cannot be prevented and that cannot prevent other gesture recognizers. Add it to the map view, and then use the gestureRecognizer’s touchesBegan, touchesMoved, etc. to your fancy.

    How to detect any tap inside an MKMapView (sans tricks)

    WildcardGestureRecognizer * tapInterceptor = [[WildcardGestureRecognizer alloc] init];
    tapInterceptor.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
            self.lockedOnUserLocation = NO;
    };
    [mapView addGestureRecognizer:tapInterceptor];
    

    WildcardGestureRecognizer.h

    //
    //  WildcardGestureRecognizer.h
    //  Copyright 2010 Floatopian LLC. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    typedef void (^TouchesEventBlock)(NSSet * touches, UIEvent * event);
    
    @interface WildcardGestureRecognizer : UIGestureRecognizer {
        TouchesEventBlock touchesBeganCallback;
    }
    @property(copy) TouchesEventBlock touchesBeganCallback;
    
    
    @end
    

    WildcardGestureRecognizer.m

    //
    //  WildcardGestureRecognizer.m
    //  Created by Raymond Daly on 10/31/10.
    //  Copyright 2010 Floatopian LLC. All rights reserved.
    //
    
    #import "WildcardGestureRecognizer.h"
    
    
    @implementation WildcardGestureRecognizer
    @synthesize touchesBeganCallback;
    
    -(id) init{
        if (self = [super init])
        {
            self.cancelsTouchesInView = NO;
        }
        return self;
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (touchesBeganCallback)
            touchesBeganCallback(touches, event);
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
    {
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
    }
    
    - (void)reset
    {
    }
    
    - (void)ignoreTouch:(UITouch *)touch forEvent:(UIEvent *)event
    {
    }
    
    - (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer
    {
        return NO;
    }
    
    - (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer
    {
        return NO;
    }
    
    @end
    

    SWIFT 3

    let tapInterceptor = WildCardGestureRecognizer(target: nil, action: nil)
    tapInterceptor.touchesBeganCallback = {
        _, _ in
        self.lockedOnUserLocation = false
    }
    mapView.addGestureRecognizer(tapInterceptor)
    

    WildCardGestureRecognizer.swift

    import UIKit.UIGestureRecognizerSubclass
    
    class WildCardGestureRecognizer: UIGestureRecognizer {
    
        var touchesBeganCallback: ((Set<UITouch>, UIEvent) -> Void)?
    
        override init(target: Any?, action: Selector?) {
            super.init(target: target, action: action)
            self.cancelsTouchesInView = false
        }
    
        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
            super.touchesBegan(touches, with: event)
            touchesBeganCallback?(touches, event)
        }
    
        override func canPrevent(_ preventedGestureRecognizer: UIGestureRecognizer) -> Bool {
            return false
        }
    
        override func canBePrevented(by preventingGestureRecognizer: UIGestureRecognizer) -> Bool {
            return false
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.