Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent touch event on object behind contentView #85

Open
52616e646f6d4279746573 opened this issue May 20, 2015 · 2 comments
Open

Prevent touch event on object behind contentView #85

52616e646f6d4279746573 opened this issue May 20, 2015 · 2 comments

Comments

@52616e646f6d4279746573
Copy link

Hi,

I am trying to setup a callout that is roughly 200 x 200 is size. The callout pops up fine size is correct. I used a UIView and set contentView = myUIView.

I need to trigger a function when user press on callout. Instead it will dismiss the callout. As well if there is an annotation under the calloutView, it will select this annotation and show a new callout view.

How would I go about preventing the callout from being dismissed as well as firing a function on touch?

Thanks.

@nfarina
Copy link
Owner

nfarina commented May 20, 2015

Are you using the callout view inside Apple's MKMapView? If so, you need to do a bit of work to make touch handling work properly. Take a look at MapKitComparisonController.m towards the bottom, in the included CalloutSamples app.

@52616e646f6d4279746573
Copy link
Author

Yes I am using MKMapView.

Following your advice, I have looked through the example again and created a custom subclass of MKMapView. But it still does not seem to work. here is my code for the subclass. I can't seem to get it to work, It crashes as soon as I touch the map.

 class mapSub : MKMapView {

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer!, shouldReceiveTouch touch: UITouch!) -> CBool {

    println(touch.view)
    if touch.view .isKindOfClass(UIControl) {
         println("no dice")
        return false
    }
    else {
        println("make it so Geordie")
        return true
    }
}

override func hitTest(point: CGPoint, withEvent e: UIEvent?) -> UIView? {

    if let cM:UIView = self.hitTest(calloutView.convertPoint(point, fromView: self), withEvent: e)
    {
        println("direct hit")
        return cM
    }

    return super.hitTest(point, withEvent: e)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants