【问题标题】:Removing subviews from MapPin从 MapPin 中删除子视图
【发布时间】:2016-04-18 10:02:06
【问题描述】:

在我的 Swift 应用程序中,我按照本教程将自定义图钉和标注添加到我的地图视图。我的代码几乎一模一样:https://github.com/wircho/CustomMapViewCallout

每隔几分钟,我就会尝试通过清除当前注释和标注来刷新地图数据。

我的 pin 类是 CustomPin,我的标注类是 CustomCallout。

我试过了:

for subview in self.view.subviews {
            if (subview is CustomPin) {
                print(subview)
                subview.removeFromSuperview()
            }
        }

但这并没有移除我的别针。如何从我的地图视图中删除我的图钉和标注子视图?

【问题讨论】:

    标签: ios swift mkmapview mkannotationview


    【解决方案1】:

    您可以创建一个计时器并将其设置为 5 分钟,然后调用一个函数来删除您的引脚。

    var timer = NSTimer()
    

    在您的viewDidLoad 中设置此行

    // 300 is 5 minutes
    timer = NSTimer.scheduledTimerWithTimeInterval(300, target: self, selector: Selector("removePins"), userInfo: nil, repeats: true)
    

    遍历您的注释并删除它们

    func removePins(){
        for annotation in mapView.annotations as [MKAnnotation] {
            mapView.removeAnnotation(annotation)
        }
    }
    

    【讨论】:

    猜你喜欢
    • 2011-01-25
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多