0

I am iOS developer. I am trying to show custom callout view click on (pin).This callout view is contain two button. I have been tried to show custom callout view with these below given code.

       func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {

    var calloutSize:CGSize = CGSizeMake(200.0, 110.0)
    confirm = MKAnnotationView(frame: CGRect(x: -calloutSize.width/2, y: -calloutSize.height - 10, width: calloutSize.width, height:calloutSize.height))

    confirm!.backgroundColor = UIColor(white: 0.9, alpha: 1)
    confirm!.alpha = 0.7


    let button_Yes = UIButton(frame: CGRectMake(0, 0, 200, 54))
    button_Yes.backgroundColor = UIColor.purpleColor()
    button_Yes.setTitle("See listing detail", forState: UIControlState.Normal)
    button_Yes.addTarget(self, action:Selector( "checkout:"), forControlEvents: UIControlEvents.TouchUpInside)
    button_Yes.userInteractionEnabled = true
    button_Yes.tag = 1
    confirm!.addSubview(button_Yes)

    let button_No = UIButton(frame: CGRectMake(0,calloutSize.height / 2, 200, 54))

    button_No.backgroundColor = UIColor.purpleColor()
    button_No.setTitle("Get directions", forState: UIControlState.Normal)
    button_No.addTarget(self, action:Selector("checkin:"), forControlEvents: UIControlEvents.TouchUpInside)
    button_No.userInteractionEnabled = true
    button_No.tag = 2
    confirm!.addSubview(button_No)

    view.addSubview(confirm!)

}

func mapView(mapView: MKMapView!, didDeselectAnnotationView view: MKAnnotationView!) {

    confirm!.removeFromSuperview()
}

I have embedded a image url, i want to like this callout

Sankalap Yaduraj Singh
  • 1,167
  • 2
  • 14
  • 32
  • So what's the exact problem or question? By the way, I suggest using a plain UIView instead of creating an MKAnnotationView for the callout view. –  May 05 '15 at 11:13
  • The exact problem is that, when am i select pin then a custom annotation show with two button like row. And i am also use UIView but this is not working. Please look a image url for your understanding. – Sankalap Yaduraj Singh May 05 '15 at 11:28
  • You need to explain in detail what "not working" means. Compiler error, run-time error, something else -- be precise -- what happens exactly? What debugging did you do? Using an MKAnnotationView for the _callout_ view is not recommended. –  May 05 '15 at 11:45
  • My callout view are showing click on pin but these button action not per form and there is not generating error. when i am click on button then callout view remove from map view. – Sankalap Yaduraj Singh May 05 '15 at 12:19
  • See http://stackoverflow.com/questions/28066623/customise-ios8-callout-bubble-swift. Implement hitTest inside a custom MKAnnotationView (but notice the _callout_ view the annotation view creates is a UIView). –  May 05 '15 at 12:24
  • and please look the image url@ – Sankalap Yaduraj Singh May 05 '15 at 12:29
  • i have face a error: use of unresolved identifier "updatePinPosition" – Sankalap Yaduraj Singh May 05 '15 at 12:36
  • and where this code put.. @if calloutState == .Expanded && CGRectContainsPoint(tableView.frame, viewPoint) { view = tableView.hitTest(convertPoint(viewPoint, toView: tableView), withEvent: event) } – Sankalap Yaduraj Singh May 05 '15 at 12:39
  • This code is not working. – Sankalap Yaduraj Singh May 06 '15 at 05:25
  • any body help me, to make a callout view on annotation selected. i have attached image for your better understanding. – Sankalap Yaduraj Singh Jun 12 '15 at 09:10

1 Answers1

-1

For this you need to create subclass of MKAnnotationView and XIB, Using this you can return your custom view for callout in

mapView(_:viewForAnnotation:)

Here are the best examples : https://www.cocoacontrols.com/controls/gikanimatedcallout https://www.cocoacontrols.com/controls/multirowcalloutannotationview

Hitendra Solanki
  • 4,871
  • 2
  • 22
  • 29