- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我想一次性删除 map 上的所有叠加层,我尝试了不同的方法,但都行不通。
上次尝试我做了 [self.mapView removeOverlays:self.mapView.overlays];
但它仍然不起作用。知道如何删除这些覆盖层吗?
谢谢。
更新 1
我有错误:malloc: *** 对象 0x5adc0c0 错误:未分配正在释放的指针
*** 在malloc_error_break 设置断点调试
我想我知道为什么,但真的不知道如何解决...这是我需要在 mapView 上绘制另一条线时的代码:
// Create a c array of points.
MKMapPoint *pointsArray = malloc(sizeof(CLLocationCoordinate2D) * 2);
// Create 2 points.
MKMapPoint startPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(oldLatitude, oldLongitude));
MKMapPoint endPoint = MKMapPointForCoordinate(CLLocationCoordinate2DMake(newLatitude, newLongitude));
// Fill the array.
pointsArray[0] = startPoint;
pointsArray[1] = endPoint;
// Erase polyline and polyline view if not nil.
if (self.routeLine != nil) {
[_routeLine release];
self.routeLine = nil;
}
if (self.routeLineView != nil) {
[_routeLineView release];
self.routeLineView = nil;
}
// Create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointsArray count:2];
// Add overlay to map.
[self.mapView addOverlay:self.routeLine];
// clear the memory allocated earlier for the points.
free(pointsArray);
// Save old coordinates.
oldLatitude = newLatitude;
oldLongitude = newLongitude;
所以我释放了 routeLine
对象,它是之前的覆盖层。所以当我试图删除它时,它崩溃了,因为它已经被释放了。
这是用于添加覆盖 View 的 mapView 委托(delegate)的代码:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayView* overlayView = nil;
if(overlay == _routeLine) {
// If we have not yet created an overlay view for this overlay, create it now.
if(self.routeLineView == nil) {
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:_routeLine] autorelease];
self.routeLineView.fillColor = [UIColor blueColor];
self.routeLineView.strokeColor = [UIColor blueColor];
// Size of the trace.
self.routeLineView.lineWidth = routeLineWidth;
}
overlayView = self.routeLineView;
}
return overlayView;
}
如果你们知道我如何解决这个问题,从我的 MKMapView 中删除所有叠加层,那就太棒了!
更新 2
我试着不释放我的 routeLine
和 routeLineView
对象,现在它可以工作了。似乎也没有泄漏。所以现在我正在这样做:
// Erase polyline and polyline view if not nil.
if (self.routeLine != nil) {
//[_routeLine release];
self.routeLine = nil;
}
if (self.routeLineView != nil) {
//[_routeLineView release];
self.routeLineView = nil;
}
最佳答案
当您调用 removeOverlays:
时, map View 将释放 MKOverlay 和 MKOverlayView 对象。
您在 _routeLine
和 _routeLineView
中拥有自己的引用。
调用removeOverlays:
后,您的变量将指向已释放的内存。当您重新创建多段线时,您会过度释放,然后导致崩溃。
因此删除release
调用:
if (_routeLine != nil) {
[_routeLine release]; // <-- remove this
self.routeLine = nil;
}
if (_routeLineView != nil) {
[_routeLineView release]; // <-- remove this
self.routeLineView = nil;
}
关于iOS 删除 MKMapView 叠加层不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6375266/
在我当前设计的应用程序中,我有一个带有覆盖层的 MKMapView (顺便说一句,自定义的 MKPolylines),我希望能够检测到触摸事件这些覆盖层并为每个覆盖层分配特定的操作。有人可以帮我解决这
我在我的 .xib 上放置了一个 MKMapView。 它工作正常,但我需要 map 根据罗盘方向旋转? 我读过有关“指南针模式”的内容。 也许我需要将 compassMode 的 MKMapView
我有一个带有注册委托(delegate)的 MKMapView,因此我可以监听区域更改事件(具体来说,regionDidChangeAnimated)。我正在寻找一种可靠的方法来判断区域更改事件是用户
我正在尝试将 MKAnnotationView 添加到 MKMapView 但我做不到……有人能帮我吗? 这是我的代码: override func viewDidLoad() { super
我想像照片应用程序中那样隐藏和显示导航栏但不会丢失 MKMapView 的功能。用户仍然应该能够双击进行缩放、捏合和缩放,并能够选择注释。 我试过: UITapGestureRecognizer*
我在 MKMapView 上有一个 MKCircle。它是用户可拖动的,但如果用户拖动圆圈外的区域, map 应该会移动。 - (IBAction)createPanGestureRecognizer
我正在开发一款与 map 配合使用的 iPhone 应用程序。在此应用程序中,我需要根据纬度和经度显示一些 parking 位(地址)。至此,我成功完成了,但我想显示相对于用户方向(SE、SW、NE、
如何比较 MKMapView 的当前跨度?我正在使用以下代码: - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)a
我们在我们的一个应用程序中看到了意外行为 - 我们在一个屏幕上显示 map View 上的注释,用户可以通过单击按钮更改显示的注释。 当我们用 iOS7 重建应用程序时,屏幕会定期卡住,即一旦下面的代
我正在尝试创建一个带有 MKMapView 和一个导航到用户位置的按钮的 SwiftUI View 。以下是我的全部代码。我创建了一个名为 MapView 的 View ,它符合 UIViewRepr
我的代码在iOS 7到8上运行良好。昨天进行了更新,我的图钉上的自定义图像已替换为标准的图钉图像。 有什么建议? 我的代码: extension ViewController: MKMapViewDe
我可以使用 MKMApView 组件创建一个 iOS 商业应用程序(在应用程序商店中花费几美元下载)吗? 我知道它是基于 Google 图片,所以...我不知道。 最佳答案 当然,MapKit 已用于
我有用户位置和边界。边界有8个坐标。我需要检查用户是否在边界内。我正在 iPhone 中使用 MapView。 提前致谢。 最佳答案 使用 Map Kit 中的一些内置函数来执行此操作的一种方法是将边
我有一个 MkMapView,并希望将 map 保持在用户位置的中心,就像按下范围按钮时 iPhone map 应用程序所做的那样。 我使用 setCenterCoordinate 方法,因为我不需要
浏览了这里的一些问题后,我对缩放级别和 MKMapView 有了一个大概的了解。然后我发现了这个很棒的博客: http://troybrant.net/blog/2010/01/set-the-zoo
我有一个使用以下代码删除 pin 的功能: ParkPlaceMark *placemark=[[ParkPlaceMark alloc] initWithCoordinate:location];
双击 MKMapView 时:放大。 但是如何缩小呢? 最佳答案 总是使用两根手指来放大和缩小。在模拟器上,您需要按住选项键才能在模拟屏幕上显示“两根手指”(我认为这是 Alt 键,但我在 Mac 上
释放 MKMapView 后,我遇到了奇怪的(?)崩溃。 MKMapView 是我的 View Controller 中的 subview ,在我从导航堆栈中删除该 View 并释放它后,应用程序崩溃
我通过单击按钮缩小 map 。 因此,本地图完全缩小时,如果我尝试再次缩小它,那么它在设置区域时会崩溃。 不确定,但是,有没有办法检测 map 是否达到最大缩放限制? 这是我缩小 map 的代码 -(
我需要获得某种比例因子,它可以告诉我 map 缩放了多少(每当区域发生变化时)。 我的第一个想法是使用跨度的纬度或经度增量值。我会跟踪“旧”值,然后在 map 区域发生变化时更新该值,并将比率与旧值进
我是一名优秀的程序员,十分优秀!