{"id":2696,"date":"2021-04-30T16:15:32","date_gmt":"2021-04-30T08:15:32","guid":{"rendered":"http:\/\/123.57.164.21\/?p=2696"},"modified":"2021-04-30T16:15:32","modified_gmt":"2021-04-30T08:15:32","slug":"ios-mapkit-%e8%87%aa%e5%ae%9a%e4%b9%89%e7%9a%84%e5%9b%be%e9%92%89%e5%9c%a8%e7%94%bb%e9%9d%a2%e6%98%be%e7%a4%ba%e6%97%b6%e7%9a%84%e4%bc%98%e5%85%88%e7%ba%a7","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=2696","title":{"rendered":"IOS MapKit \u81ea\u5b9a\u4e49\u7684\u56fe\u9489\u5728\u753b\u9762\u663e\u793a\u65f6\u7684\u4f18\u5148\u7ea7"},"content":{"rendered":"\n<p>\u5728IOS\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528MapKit\u4f7f\u7528\u82f9\u679c\u7684\u5730\u56fe\uff0c\u5728\u5730\u56fe\u4e0a\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u56fe\u9489\uff0c\u5047\u5982\u56fe\u9489\u90fd\u52a0\u5728\u4e00\u8d77\uff0c\u4e92\u76f8\u5c31\u4f1a\u6709\u8986\u76d6\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u53ef\u4ee5\u7528displayPriority \u4f18\u5148\u7ea7\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/p>\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=\"\">        \/\/ \u81ea\u5b9a\u4e49\u7684MKAnnotation\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            if annotation.annotationStatus == \"normal\" {\n                let image = UIImage(named: \"\u56fe\u9489\u56fe\u7247\u540d\u5b57\")!\n                annotationView!.image = image.scaleImage(scaleSize: annotation.iconScaleSize)\n                \/\/ \u8fd9\u91cc\u8bbe\u5b9a\u56fe\u9489\u7684\u4f18\u5148\u7ea7\n                annotationView!.displayPriority = .defaultLow\n                \/\/ \u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49displayPriority\n                \/\/ annotationView!.displayPriority = .init(30)\n            }\n\n            if annotation.annotationStatus == \"selected\" {\n                let image = UIImage(named: \"\u56fe\u9489\u56fe\u7247\u540d\u5b57\")!\n                annotationView!.image = image.scaleImage(scaleSize: 2)\n                \/\/ \u8fd9\u91cc\u8bbe\u5b9a\u56fe\u9489\u7684\u4f18\u5148\u7ea7\n                annotationView!.displayPriority = .defaultHigh\n                \/\/ \u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49displayPriority\n                \/\/ annotationView!.displayPriority = .init(40)\n            }\n\n            return annotationView\n        }\n    }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728IOS\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528MapKit\u4f7f\u7528\u82f9\u679c\u7684\u5730\u56fe\uff0c\u5728\u5730\u56fe\u4e0a\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u56fe\u9489\uff0c\u5047\u5982\u56fe\u9489\u90fd\u52a0\u5728\u4e00\u8d77\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,8],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2696"}],"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=2696"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2696\/revisions"}],"predecessor-version":[{"id":2697,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/2696\/revisions\/2697"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}