Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在Swift中的同一地图视图中指定多个注释Pincolor?_Ios_Iphone_Xcode_Swift_Annotations - Fatal编程技术网

Ios 在Swift中的同一地图视图中指定多个注释Pincolor?

Ios 在Swift中的同一地图视图中指定多个注释Pincolor?,ios,iphone,xcode,swift,annotations,Ios,Iphone,Xcode,Swift,Annotations,因此,我有一个地图视图,在用户在不同位置发布时添加了注释。我正在尝试将pin颜色更改为绿色、红色或紫色,具体取决于pin创建后的时间 我在这里遇到的问题是,所有管脚都希望更改为一种指定的颜色,而不是用不同的颜色显示管脚。我似乎不知道这里出了什么问题。在下面的示例代码中,它将所有管脚设置为绿色,而实际上,只有在不到4小时前创建的管脚才应为绿色,红色管脚大于4小时但小于44小时,紫色管脚大于44小时 感谢您的帮助 pinColorQuery.findObjectsInBackgroundWithBl

因此,我有一个地图视图,在用户在不同位置发布时添加了注释。我正在尝试将pin颜色更改为绿色、红色或紫色,具体取决于pin创建后的时间

我在这里遇到的问题是,所有管脚都希望更改为一种指定的颜色,而不是用不同的颜色显示管脚。我似乎不知道这里出了什么问题。在下面的示例代码中,它将所有管脚设置为绿色,而实际上,只有在不到4小时前创建的管脚才应为绿色,红色管脚大于4小时但小于44小时,紫色管脚大于44小时

感谢您的帮助

pinColorQuery.findObjectsInBackgroundWithBlock {
            (dateCreated, error) -> Void in
            if error == nil {
                // The find succeeded.

                let createdDates = dateCreated as! [PFObject]

                for date in createdDates {
                    let createdAt = date.createdAt as NSDate!
                    let currentDate = NSDate()
                    let expirationDate = currentDate.timeIntervalSinceDate(date.createdAt!)

                    //This is where I attempt to set the pinColor based on age of pin
                    if (expirationDate < 18000) {
                        normalPinView!.pinColor = .Green
                    } else if (expirationDate < 162000) {
                        normalPinView!.pinColor = .Red
                    } else if (expirationDate > 162050) {
                        normalPinView!.pinColor = .Purple
                    }

                }

            } else {
                // Log details of the failure
                println("Error: \(error!) \(error!.userInfo!)")
            }
        }
pinColorQuery.findObjectsInBackgroundWithBlock{
(dateCreated,错误)->中的Void
如果错误==nil{
//发现成功了。
让createdDates=dateCreated as![PFObject]
用于createdDates中的日期{
让createdAt=date.createdAt作为NSDate!
让currentDate=NSDate()
让expirationDate=currentDate.timeIntervalSinceDate(date.createdAt!)
//这就是我试图根据针的年龄设置pinColor的地方
如果(到期日<18000){
normalPinView!.pinColor=.Green
}否则,如果(到期日期<162000){
normalPinView!.pinColor=.Red
}否则如果(到期日期>162050){
normalPinView!.pinColor=.Purple
}
}
}否则{
//记录故障的详细信息
println(“错误:\(错误!)\(错误!.userInfo!)”)
}
}

expirationDate间隔返回正确,我用一个简单的
println(“\(expirationDate)”)进行了检查。
我在mapview上使用过相同的功能,但使用了objective-c。这不会直接更改已添加批注的pin颜色。解决方法是枚举所有注释并应用pincolor逻辑,如果pincolor中有更改,请使用新pincolor创建新注释,但使用旧数据源,然后删除旧注释并在同一位置添加新注释。就个人而言,它肯定会起作用,这是实际的解决办法。在我的应用程序中,如果帖子的评论数超过10、50等等,我会改变pin颜色和pin大小

Objective-c代码:在某些函数中

for (int i =0; i < [self.mapView.annotations count]; i++)
{
   if ([[self.mapView.annotations objectAtIndex:i] isKindOfClass:[CustomAnnotation class]])
{
     CustomAnnotationClass *annotation=[self.mapView.annotations objectAtIndex:i];

    if (annotation.expirationDuration <= 18000)
     {
         CustomAnnotationClass *newAnnotation = annotation;
         newAnnotation.pinColor = purple;
         [self.mapView removeAnnotation:[self.mapView.annotations objectAtIndex:i]];
         [self.mapView addAnnotation:newAnnotation];
      }

      }
}
for(int i=0;i<[self.mapView.annotations count];i++)
{
如果([[self.mapView.annotations objectAtIndex:i]是KindofClass:[CustomAnnotation class]])
{
CustomAnnotationClass*annotation=[self.mapView.annotations对象索引:i];

if(annotation.expirationDuration)好的,所以我有点理解你的意思,但我不知道我到底是如何将其转化为代码的?@Zach我编辑了我的答案,其中包含一些粗略的代码。如果你不理解,请告诉我我将用swift提供给你。你能用swift提供吗?这让我非常困惑:(