在 Swift 中,我将尝试在顶部设置引脚位置(zPosition),我在地图上添加 10 个引脚,当前引脚(任何一个引脚)显示在顶部,这些当前引脚图像发生变化,但它没有显示在顶部,请帮助我这是我的代码我有尝试这些代码
// 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
}
我还有一个问题,我们可以选择缩放以一起显示所有 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];
请帮我解决这两个点相关地图谢谢