【问题标题】:Swift viewForAnnotation pin zposition not on topSwift viewForAnnotation pin zposition不在顶部
【发布时间】: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


【解决方案1】:

关于第一点,我也有同样的问题。错误在于那行代码pinView!.superview!.bringSubviewToFront(view)。 当你想把 pinView 带到前面时,你必须这样做pinView!.superview!.bringSubviewToFront(pinView)。 因为您获取 pinView 的超级视图并且必须将该 pinView 设置为前面。对我来说,它正在工作。

【讨论】:

    猜你喜欢
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 2012-10-11
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多