【发布时间】:2016-05-10 06:32:35
【问题描述】:
在 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];
请帮我解决这两个点到相关地图 谢谢你
【问题讨论】:
-
也许一些截图会有所帮助。
-
好的,我会添加,但问题是我有 10 个引脚 9 个引脚相同,1 个引脚是另一个图像,所以这些引脚不想回到其他引脚,我必须设置在上面
标签: ios swift dictionary pins