ios - Swift viewForAnnotation pin zposition 不在顶部

标签 ios swift dictionary pins

在 Swift 中,我将尝试在顶部设置引脚位置 (zPosition),我在 map 上添加 10 个引脚,当前引脚(任何一个引脚)显示在顶部并且这些当前引脚图像发生变化,但它没有显示在顶部,请帮助我这是我的代码 我有尝试这些代码

// pinView!.layer.zPosition = 1
//pinView?.bringSubviewToFront(self.view)
pinView!.superview!.bringSubviewToFront(view)

应用在这些行崩溃

pinView!.superview!.bringSubviewToFront(view)

然后返回我 fatal error :在展开可选值时意外发现 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 个图钉 任何解决方案对于这些点如何设置缩放杆,相机级别以在 map View 上显示所有 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]; 

请帮我解决这两个点到相关 map 谢谢你

最佳答案

关于第一点,我也有同样的问题。错误在于那行代码 pinView!.superview!.bringSubviewToFront(view)。 因为你想把 pinView 带到前面,你必须像这样 pinView!.superview!.bringSubviewToFront(pinView)。 因为您使用 pinView 的 super View 并且必须将该 pinView 设置为前面。对我来说它的工作。

关于ios - Swift viewForAnnotation pin zposition 不在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37130858/

相关文章:

swift - 字典映射认为一个字符串是一个字符串数组

ios - 如何从 HealthKit 获取每日平均步数

swift - 从 App Delegate 执行 Segue - Swift

java - Java Map 键的奇怪输出

ios - Swift 中的条件映射函数

swift - 使用组合时出现运行时错误 : dyld: Symbol not found: _$s7Combine9PublishedV9PublisherCyx_GAadAMc

java - 多键映射实现

ios - Apple Mach-O 链接器错误 Xcode 4.5.2

ios - 警告 : Attempt to present when segueing from table view

objective-c - iOS是否会将NSString强制转换为NSNumbers?