質問編集履歴

5

コード追加

2018/06/01 07:43

投稿

clo.momo
clo.momo

スコア27

test CHANGED
File without changes
test CHANGED
@@ -170,7 +170,7 @@
170
170
 
171
171
  mapView.removeAnnotation(view.annotation!)//機能する⭕
172
172
 
173
- print("マーカーテストmarkerView:",markerView)//マーカーテスト3markerView: <MKMarkerAnnotationView: 0x7fb2ec016e00; frame = (121.802 248.686; 28 28); layer = <CALayer: 0x60000042ace0>>
173
+ print("マーカーテス3トmarkerView:",markerView)//マーカーテスト3markerView: <MKMarkerAnnotationView: 0x7fb2ec016e00; frame = (121.802 248.686; 28 28); layer = <CALayer: 0x60000042ace0>>
174
174
 
175
175
  }
176
176
 

4

コード追加

2018/06/01 07:43

投稿

clo.momo
clo.momo

スコア27

test CHANGED
File without changes
test CHANGED
@@ -106,6 +106,10 @@
106
106
 
107
107
 
108
108
 
109
+ print("マーカーテストmarkerView:",markerView)//マーカーテストmarkerView: <MKMarkerAnnotationView: 0x7fb2ec016e00; frame = (121.802 248.686; 28 28); layer = <CALayer: 0x60000042ace0>>
110
+
111
+
112
+
109
113
  //左ボタンをアノテーションビューに追加する。
110
114
 
111
115
  let leftButton = UIButton()
@@ -158,7 +162,7 @@
158
162
 
159
163
  markerView.markerTintColor = .blue//機能しない❌
160
164
 
161
- print("markerView:",markerView)
165
+ print("マーカーテスト2markerView:",markerView)//表示なし
162
166
 
163
167
  } else {
164
168
 
@@ -166,6 +170,8 @@
166
170
 
167
171
  mapView.removeAnnotation(view.annotation!)//機能する⭕
168
172
 
173
+ print("マーカーテストmarkerView:",markerView)//マーカーテスト3markerView: <MKMarkerAnnotationView: 0x7fb2ec016e00; frame = (121.802 248.686; 28 28); layer = <CALayer: 0x60000042ace0>>
174
+
169
175
  }
170
176
 
171
177
  }

3

コードを追加

2018/06/01 07:42

投稿

clo.momo
clo.momo

スコア27

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,113 @@
61
61
  }
62
62
 
63
63
  ```
64
+
65
+
66
+
67
+ メソッドの全コードです。
68
+
69
+ ```Swift
70
+
71
+      markerView = MKMarkerAnnotationView()
72
+
73
+
74
+
75
+ //選択したアノテーションにボタンを追加する
76
+
77
+ func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
78
+
79
+ if annotation is MKUserLocation {
80
+
81
+ return nil
82
+
83
+ }
84
+
85
+
86
+
87
+ //マーカーアノテーションにコールアウトを表示
88
+
89
+ markerView.canShowCallout = true
90
+
91
+ let pinID = "pin"
92
+
93
+ var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: pinID) as? MKMarkerAnnotationView
94
+
95
+ if annotationView == nil {
96
+
97
+ annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: pinID)
98
+
99
+ //マーカー設置の時アニメーションをつける
100
+
101
+ markerView.animatesWhenAdded = true
102
+
103
+ //マーカーを緑にする
104
+
105
+ markerView.markerTintColor = .green//機能する⭕
106
+
107
+
108
+
109
+ //左ボタンをアノテーションビューに追加する。
110
+
111
+ let leftButton = UIButton()
112
+
113
+ leftButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
114
+
115
+ leftButton.setTitle("????", for: UIControlState.normal)
116
+
117
+ leftButton.setTitleColor(UIColor.black, for: UIControlState.normal)
118
+
119
+ markerView.detailCalloutAccessoryView = leftButton
120
+
121
+
122
+
123
+ //右ボタンをアノテーションビューに追加する。
124
+
125
+ let rightButton = UIButton()
126
+
127
+ rightButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
128
+
129
+ rightButton.setTitle("❌", for: UIControlState.normal)
130
+
131
+ rightButton.setTitleColor(UIColor.black, for: UIControlState.normal)
132
+
133
+ markerView.rightCalloutAccessoryView = rightButton
134
+
135
+
136
+
137
+ } else {
138
+
139
+ annotationView!.annotation = annotation
140
+
141
+ }
142
+
143
+
144
+
145
+ return markerView
146
+
147
+ }
148
+
149
+
150
+
151
+ //吹き出しアクササリー押下時の呼び出しメソッド
152
+
153
+ func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
154
+
155
+ // 左ボタンが押された場合は青に変える
156
+
157
+ if(control == view.leftCalloutAccessoryView) {
158
+
159
+ markerView.markerTintColor = .blue//機能しない❌
160
+
161
+ print("markerView:",markerView)
162
+
163
+ } else {
164
+
165
+ //右のボタンが押された場合はピンを消す。
166
+
167
+ mapView.removeAnnotation(view.annotation!)//機能する⭕
168
+
169
+ }
170
+
171
+ }
172
+
173
+ ```

2

コードミス

2018/06/01 07:34

投稿

clo.momo
clo.momo

スコア27

test CHANGED
File without changes
test CHANGED
@@ -10,13 +10,13 @@
10
10
 
11
11
  0. control == view.leftCalloutAccessoryView が間違っている?
12
12
 
13
- 0. 念の為 markerView.markerTintColor = .green をelse{}に入れてみたら色が変わらない
13
+ 0. 念の為 markerView.markerTintColor = .blue をelse{}に入れてみたら色が変わらない
14
14
 
15
- 0. ということは、markerView.markerTintColor = .green は mapView:calloutAccessoryControlTapped では使えない
15
+ 0. ということは、markerView.markerTintColor は mapView:calloutAccessoryControlTapped では使えない
16
16
 
17
17
 
18
18
 
19
- では、markerView.markerTintColor = .green を使わずにアノテーションの色を変えるにはどうすればいいのでしょうか?
19
+ では、markerView.markerTintColor を使わずにアノテーションの色を変えるにはどうすればいいのでしょうか?
20
20
 
21
21
 
22
22
 

1

コード間違い

2018/06/01 04:55

投稿

clo.momo
clo.momo

スコア27

test CHANGED
File without changes
test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
            //機能しない ❌
50
50
 
51
- markerView.markerTintColor = .green
51
+ markerView.markerTintColor = .blue
52
52
 
53
53
  } else {
54
54