I am using SMCalloutView To create a custom callout for my mapView. The problem I am running into is when the callout view is visible and the user presses on the callout, if another annotation is under the callout view it will dismiss the current selected annotation and select the one under the visible callout view.
I thought that maybe I could create a UIView subclass to catch all the touch events. So I created a UIView subclass, all the functions fire correctly if I add it directly to the mapView. But when I use it for the popover it doesn't seem to work at all.
import Foundation
import UIKit
class popOverSub: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
let myTap = UITapGestureRecognizer(target: self, action: "touchEventTest")
addGestureRecognizer(myTap)
userInteractionEnabled = true
backgroundColor = UIColor.greenColor()
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func touchEventTest() {
println("touchEventTest")
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
println("touch begins")
}
}
For sake of completion here is where I call the custom CalloutView.
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
let popView = popOverSub(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
calloutView.contentView = popView
self.calloutView.calloutOffset = CGPoint(x: view.frame.width*0.5, y: 0)
self.calloutView.delegate = self
calloutView.presentCalloutFromRect(calloutView.bounds, inLayer: view.layer, constrainedToLayer: self.mapView.layer, animated: true)
}
What I need to do. If user presses on callout view, it does not dismiss the callout, or pass the touch event to the mapView/Annotation underneath . Instead it needs to call a function. Any tips would be great.