是否可以在iOS 11中自定义群集映像? [英] Is it possible to customize cluster image in iOS 11?

查看:63
本文介绍了是否可以在iOS 11中自定义群集映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 11的新API,并且已经成功使集群出现.现在,我尝试更改提供自定义图像的群集图像.由于我创建了此自定义注释视图,因此:

I'm using iOS 11 new APIs and I have been successful in making cluster appear. Now, I'm trying to change cluster image providing a custom image. Since I created this custom annotation view:

    class PlaceView: MKAnnotationView {
        override var annotation: MKAnnotation? {
            willSet {
                guard let place = newValue as? Place else {return}
                clusteringIdentifier = Place.type
                image = place.image
            }
    }

我试图将这一行添加到willSet块中:

I tried to add this line inside willSet block:

cluster?.image = UIImage(named: "Cluster")

但是没有用.

我想念什么?谁能指出我正确的方向?

What am I missing? Can anyone point me in the right direction?

推荐答案

您应检查注解的类型是否为MKClusterAnnotation.如果是,则可以使用memberAnnotations属性访问成员注释.例如,您可能会说:

You should check to see if the annotation is of type MKClusterAnnotation. If it is you can then use the memberAnnotations property to access the member annotations. In your case, for example, you could say:

override var annotation: MKAnnotation?
{
    willSet
    {
        if let cluster = newValue as? MKClusterAnnotation { 
            image = UIImage(named: "Cluster")
        } else {
            // set image for non cluster
        }
    }
}

有关更多信息,请参阅WWDC 2017 MapKit的新增功能.

For more information see WWDC 2017 What's New with MapKit.

这篇关于是否可以在iOS 11中自定义群集映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆