Generate pop-over for map pin (announcement)

Asked 2 years ago, Updated 2 years ago, 30 views

I want the balloon to stick to the pin like Apple's standard map
I use storyBoard for screen transition

Screen Transition Methods

 func mapView (mapView:MKMapView, viewForAnnotation:MKAnnotation) ->MKAnnotationView? {
    if announcement is MKUserLocation {
        return nil
    }

    // Identifier
    let myAnnotationIdentifier="myAnnotation"

    // Request AnnotationView
    var myAnnotationView: MKAnnotationView!=mapView.dequeueReusableAnnotationViewWithIdentifier (myAnnotationIdentifier)

    // Setting the button to the right of the annotation
    let button —UIButton = UIButton (type: UIButtonType.InfoLight)
    if myAnnotationView == nil {
        myAnnotationView = MKPinAnnotationView (annotation:annotation, reuseIdentifier: myAnnotationIdentifier)

        // Attach a button to the right of the annotation
        myAnnotationView.rightCalloutAccessoryView=button
        myAnnotationView.canShowCallout=true
    }
    return myAnnotationView
}

funcmapView(mapView:MKMapView, announcementView:MKAnnotationView, calloutAccessoryControlTapped control:UIControl){

    print("tapped")
    self.performSegueWithIdentifier("detailController", sender:view)

}

It's like this."I would like to attach the button ""i"" to the right side of the pin, and pop over the detail screen appears by tapping the button."

StoryBoard has two views: Map view and Popover view.
storyBoard

"Here, I have to specify a balloon in the item ""anchor"", but how should I describe the pin in the map?"
Thank you for your cooperation.

ios swift

2022-09-30 16:53

1 Answers

Pins are generated dynamically while running the app, so it will be difficult to specify them as Anchors on the Storyboard.

This is the first time I've tried implementing Popover display on the Storyboard, but as you said, if I don't set Anchor, I get an error and the app build fails, so I don't think it's possible to specify Anchor alone by code.

This means that we have no choice but to stop setting Segue on the Storyboard and display Popover only with code.For more information on how to display Popover only by code, see the specific code in the UIPopoverPresentationController document:

UIPoverPresentationController Class Reference
※ For some reason, the code appears only in the Objective-C version of the document.


2022-09-30 16:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.