Swift では、ピンの位置 (zPosition) を上に設定しようとします。マップに 10 個のピンを追加します。現在のピン (任意の 1 つのピン) が上に表示され、これらの現在のピンの画像が変更されます。しかし、上に表示されません。助けてくださいme これが私のコードです 私はこれらのコードを試してください
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
これらの行でのアプリのクラッシュ
pinView!.superview!.bringSubviewToFront(view)
そしてそれは私に致命的なエラーを返し ます:オプションの値をアンラップ中に予期せずnilが見つかりました
これが私のコードです
func mapView(mapView: MKMapView,
viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MyAnnotation == false{
return nil
}
/* First typecast the annotation for which the Map View has
fired this delegate message */
let senderAnnotation = annotation as! MyAnnotation
// -------------------------- For ios 9 -------------------
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if pinView == nil {
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
}else{
pinView!.annotation = annotation
}
pinView!.tag = senderAnnotation.getTag;
// print(senderAnnotation.getTag)
if annotation is MyAnnotation {
print(senderAnnotation.pinColor)
if(senderAnnotation.pinColor == .Red)
{
if(currentIndex == senderAnnotation.getTag)
{
print("currentIndex==\(currentIndex)********")
pinView!.image = UIImage(named: "jivemap_pin_rough_o.png")
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
}else
{
pinView!.image = UIImage(named: "jivemap_pin_rough_g.png")
}
}
else
{
if(currentIndex == senderAnnotation.getTag)
{
print("currentIndex==*********\(currentIndex)********")
pinView!.image = UIImage(named: "jivemap_pin_o.png")
// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)
}else
{
pinView!.image = UIImage(named: "jivemap_pin_g.png")
}
}
pinView!.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView
// pinView
// return pinView
}
return pinView
//return annotationView
}
もう 1 つ問題があります。ズームを選択して 10 個のピンすべてを一緒に表示できますか 任意の解決策 これらのポイントについて、ズーム レバーを設定する方法、マップ ビューに 10 個のピンすべてを表示するためのカメラ レベル これらのポイントを検索すると、これらのコードが見つかりましたが、これらのコードの使用方法を理解できません。
CGFloat latDelta = rand()*0.125/RAND_MAX - 0.02;
CGFloat lonDelta = rand()*0.130/RAND_MAX - 0.08;
CGFloat lat = 59.189358;
CGFloat lng = 18.267839;
CLLocationCoordinate2D newCoord = {lat+latDelta, lng+lonDelta};
DTSAnnotation *annotation = [DTSAnnotation annotationWithCoord:newCoord];
これらを解決するために私を助けてください 関連マップへの2つのポイント ありがとう