{"id":236,"date":"2020-07-27T11:58:27","date_gmt":"2020-07-27T03:58:27","guid":{"rendered":"http:\/\/123.57.164.21\/?p=236"},"modified":"2020-08-05T12:17:58","modified_gmt":"2020-08-05T04:17:58","slug":"mapkit-%e5%be%80%e5%9c%b0%e5%9b%be%e4%b8%8a%e6%b7%bb%e5%8a%a0mkannotation-%e5%81%8f%e7%a7%bb%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=236","title":{"rendered":"MapKit \u5f80\u5730\u56fe\u4e0a\u6dfb\u52a0MKAnnotation \u504f\u79fb\u7684\u95ee\u9898"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">iOS MapKit\u5f00\u53d1\u65f6\uff0c  \u5f80\u5730\u56fe\u4e0a\u6dfb\u52a0\u81ea\u5b9a\u4e49MKAnnotation\u56fe\u9489\u65f6\uff0c \u7ecf\u5e38\u4f1a\u9047\u5230\u56fe\u9489\u504f\u79fb\u7684\u95ee\u9898\u3002<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">       \/\/ \u30ab\u30b9\u30bf\u30e0MKAnnotation\u4f5c\u6210\n        func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {\n            guard annotation is MKPointAnnotation else { return nil }\n\n            let identifier = \"Annotation\" + String(arc4random())\n            var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)\n            if annotationView == nil {\n                annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)\n                annotationView!.canShowCallout = true\n                let btn = UIButton(type: .detailDisclosure)\n                annotationView!.rightCalloutAccessoryView = btn\n            } else {\n                annotationView!.annotation = annotation\n            \n\n            let image = UIImage(named: annotationName)!.scaleImage(scaleSize: 0.8)\n            \/\/ \u91cd\u8981\u901a\u8fc7\u8bbe\u5b9aannotationView\u7684offset\u53ef\u4ee5\u89e3\u51b3\u504f\u79fb\u7684\u95ee\u9898\n            let offset = CGPoint(x: 0, y: -(image.size.height \/ 2))\n            annotationView!.image = UIImage(named: annotationName)!.scaleImage(scaleSize: 0.8)\n            annotationView!.centerOffset = offset\n            annotationView!.displayPriority = .required\n            \n            formatAnnotation(pinView: annotationView!, forMapView: mapView)\n\n            return annotationView\n        }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>iOS MapKit\u5f00\u53d1\u65f6\uff0c \u5f80\u5730\u56fe\u4e0a\u6dfb\u52a0\u81ea\u5b9a\u4e49MKAnnotation\u56fe\u9489\u65f6\uff0c \u7ecf\u5e38\u4f1a\u9047\u5230\u56fe\u9489\u504f\u79fb\u7684\u95ee\u9898\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions\/237"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}