I have researched this problem, unfortunately I have not gotten any solutions specific to the problem.
The problem is thus:
I have a custom MKAnnotationView with drawRect overridden. I cannot use the image property because I have this property called dotColor that impacts what the annotation view draws.
Code:
class CustomAnnotationView: MKAnnotationView {
var dotColor: UIColor!
init(annotation: CustomAnnotation, color: UIColor) {
super.init(annotation: annotation, reuseIdentifier: "CustomAnnotationView")
self.annotation = annotation
frame.size = CGSize(width: 20, height: 20)
dotColor = color
opaque = false
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func drawRect(rect: CGRect) {
if annotation != nil && dotColor != nil {
let context = UIGraphicsGetCurrentContext()
let circleFrame = CGRectInset(rect, 2, 2)//Needs the inset to show the stroke completely
CGContextSetFillColorWithColor(context, UIColor.whiteColor().CGColor)
CGContextSetStrokeColorWithColor(context, dotColor.CGColor)
CGContextSetLineWidth(context, 3)
CGContextFillEllipseInRect(context, circleFrame)
CGContextStrokeEllipseInRect(context, circleFrame)
}
}
}
But when I click the annotation view on the map, it doesn't show the callout (I am pretty sure the MKAnnotation has a title. You could check out this thread's answer: "If the title is nil, the callout...")
canShowCallout
set totrue
? Afteropaque = false
, try doingcanShowCallout = true
. – user467105