質問編集履歴
3
全文公開
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,3 +35,131 @@
|
|
35
35
|
・`Xcode7.3.1`
|
36
36
|
|
37
37
|
・`Swift2.2`
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
###全文公開
|
42
|
+
|
43
|
+
```Swift
|
44
|
+
|
45
|
+
class ViewController2: UIViewController, MKMapViewDelegate {
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
@IBOutlet weak var mapView: MKMapView!
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
var data: [[String:AnyObject?]] = []
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
override func viewWillAppear(animated: Bool) {
|
58
|
+
|
59
|
+
super.viewWillAppear(animated)
|
60
|
+
|
61
|
+
self.navigationItem.title = "概要"
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
override func viewDidAppear(animated: Bool) {
|
68
|
+
|
69
|
+
super.viewDidAppear(animated)
|
70
|
+
|
71
|
+
alamoNetwork()
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
let customAnnotation = annotation as? MapAnnotationSetting
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
let identifier = "annotation"
|
86
|
+
|
87
|
+
if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("annotation") {
|
88
|
+
|
89
|
+
return annotationView
|
90
|
+
|
91
|
+
} else {
|
92
|
+
|
93
|
+
if customAnnotation?.pinImage != nil {
|
94
|
+
|
95
|
+
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
|
96
|
+
|
97
|
+
annotationView.annotation = annotation
|
98
|
+
|
99
|
+
annotationView.canShowCallout = true
|
100
|
+
|
101
|
+
annotationView.image = UIImage(named: (customAnnotation?.pinImage)!)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
return annotationView
|
106
|
+
|
107
|
+
} else {
|
108
|
+
|
109
|
+
return nil
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
|
120
|
+
|
121
|
+
view.image = UIImage(named: "sample")
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
func dropPin() {
|
128
|
+
|
129
|
+
if self.data.count > 0 {
|
130
|
+
|
131
|
+
for i in 0..<data.count {
|
132
|
+
|
133
|
+
let latitude = self.data[i]["latitude"] as? Double
|
134
|
+
|
135
|
+
let longitude = self.data[i]["longitude"] as? Double
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
let annotation = MapAnnotationSetting()
|
140
|
+
|
141
|
+
annotation.coordinate = CLLocationCoordinate2DMake(latitude!, longitude!)
|
142
|
+
|
143
|
+
annotation.pinImage = "map_01"
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
mapView.addAnnotation(annotation)
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
mapView.showAnnotations(mapView.annotations, animated: true)
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
func alamoNetwork() {
|
160
|
+
|
161
|
+
※省略※
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|
2
更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,43 +12,9 @@
|
|
12
12
|
|
13
13
|
```Swift
|
14
14
|
|
15
|
-
func mapView(mapView: MKMapView,
|
15
|
+
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
let customAnnotation = annotation as? MapAnnotationSetting
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
let identifier = "annotation"
|
24
|
-
|
25
|
-
if let annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("annotation") {
|
26
|
-
|
27
|
-
return annotationView
|
28
|
-
|
29
|
-
} else {
|
30
|
-
|
31
|
-
if customAnnotation?.pinImage != nil {
|
32
|
-
|
33
|
-
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
|
34
|
-
|
35
|
-
annotationView.annotation = annotation
|
36
|
-
|
37
|
-
annotationView.canShowCallout = true
|
38
|
-
|
39
|
-
|
17
|
+
view.image = UIImage(named: "sample")
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
return annotationView
|
44
|
-
|
45
|
-
} else {
|
46
|
-
|
47
|
-
return nil
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
}
|
52
18
|
|
53
19
|
}
|
54
20
|
|
@@ -60,6 +26,8 @@
|
|
60
26
|
|
61
27
|
`didSelectAnnotationView`のメソッドは定義済みですが、タップしてもなんの反応もしません。
|
62
28
|
|
29
|
+
イメージとしては某赤いアイコンのグルメサイトのアプリです。
|
30
|
+
|
63
31
|
|
64
32
|
|
65
33
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,4 +66,4 @@
|
|
66
66
|
|
67
67
|
・`Xcode7.3.1`
|
68
68
|
|
69
|
-
・
|
69
|
+
・`Swift2.2`
|