首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >模拟器(iOS)中的结果不一致?

模拟器(iOS)中的结果不一致?
EN

Stack Overflow用户
提问于 2016-04-27 05:08:42
回答 1查看 85关注 0票数 0

我正在构建一个基本的地理围栏应用程序,允许用户创建地理围栏,在MKMapView上查看它们,以及激活和停用它们。它基于Ray Wenderlich教程,但我已经通过几种方式对其进行了改编。也就是说,我使用Realm来持久化数据,并且创建了一个单独的LocationHandler类,它充当LocationManagerDelegate并保存一个LocationManager。通常,我会尝试将一些函数移出viewControllers并放入单独的类中。

一切似乎都正常,除了周期性的地图注释和覆盖在模拟器中不能正确呈现。大约有20%的时间,注释和覆盖图不会在应该被删除的时候被删除。或者,颜色不会像应有的那样改变。或者,圆形覆盖会改变颜色,但关联的引脚不会。

这是由于我的代码中的一些错误,还是使用模拟器的工件?谢谢你的帮助

编辑以添加一些代码:在视图控制器中

代码语言:javascript
复制
//Clicking the 'x' deletes the geofence
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,     calloutAccessoryControlTapped control: UIControl) {

        let anAnnotation = view.annotation as! GeofenceAnnotation
        let geofence = anAnnotation.geofence

        //stop monitoring geofence
        locationManager.stopMonitoringGeofence(geofence!)

        //remove representation of geofence from map
        removeGeofenceRadiusCircle((geofence?.identifier)!)
        mapView.removeAnnotation(anAnnotation)


        //delete geofence from realm
        try! realm.write {
            realm.delete(geofence!)
        }
        updateGeofenceCount()
    }
//Go through all overlays and remove appropriate one
    func removeGeofenceRadiusCircle(id: String) {
        self.mapView.delegate = self
        if let overlays = mapView?.overlays {
            for ol in overlays {
                if let circleOverlay = ol as? GeofenceRadiusCircle {
                    let aId = circleOverlay.id
                    if aId == id {
                        mapView?.removeOverlay(circleOverlay)
                        break
                    }
                }
            }
        }
    }

MKAnnotation类GeofenceAnnotation的子类: NSObject,MKAnnotation {

代码语言:javascript
复制
    var coordinate: CLLocationCoordinate2D
    var title: String?
    var subtitle: String?
    var geofence: Geofence?

    init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String,   geofence: Geofence? = nil) {
        self.coordinate = coordinate
        self.title = title
        self.subtitle = subtitle
        self.geofence = geofence
    }

MKCircle的子类

代码语言:javascript
复制
class GeofenceRadiusCircle: MKCircle{
    var geofence: Geofence?
    var color: UIColor?
    var id: String = ""
}
EN

回答 1

Stack Overflow用户

发布于 2016-04-27 23:37:38

这似乎是我这边的一个小错误,也可能是模拟器的错误。在重新绘制viewWillAppear到account之前,我需要删除旧的覆盖。这似乎解决了覆盖和注释问题。我也有一个问题,用户的位置不能一直显示在mapView中,当我在手机上运行这个应用程序时,情况似乎并非如此。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36875801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档