- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个 iOS 应用程序,它有一个 UITableView,其中包含在单元格出现时生成的 map 快照。我们使用的示例列表只是显示基于模型类中提供的纬度/经度的 map 快照。我开始注意到内存崩溃,所以我将代码减少到最低限度。当我们只做快照而不对结果做任何事情时,崩溃仍然会发生。请参阅下面的代码,它包含在我们的自定义单元格中并通过 cellForItemAtIndexPath
方法调用:
private func testMapSnapshot(viewModel: StreamViewModel)
{
let latDelta:CLLocationDegrees = 0.005
let lonDelta:CLLocationDegrees = 0.005
let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(viewModel.coordinate.latitude, viewModel.coordinate.longitude)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
let options = MKMapSnapshotOptions()
options.region = region
options.size = mapImageView.frame.size
options.scale = UIScreen.mainScreen().scale
viewModel.mapSnapshotter = MKMapSnapshotter(options: options)
viewModel.mapSnapshotter!.startWithCompletionHandler() { snapshot, error in
// do nothing
}
}
在 didEndDisplayingCell
中,我确保取消 mapSnapshotter。请参阅引用资料(我们将模型列表保留在包含 tableview 的主 VC 类中):
func collectionView(collectionView: UICollectionView, didEndDisplayingCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath)
let model = viewModel?[indexPath.item] {
model.mapSnapshotter?.cancel()
model.mapSnapshotter = nil
}
}
请注意,在执行最后一步之前,它很早就崩溃了。但是现在,如果您开始快速向下滚动列表,它就会开始卡顿并且不会停止卡顿。如果您在大约 150 行的列表中上下移动,我们将在不到 30 秒的时间内开始看到内存警告然后崩溃。
我通过 Instruments 运行了它,但它不是很有帮助。看起来 Heap 和 Anonymous VM 分配正在逐渐增加,可能导致崩溃。请参阅引用:
我看到了这个帖子: MKMapSnapshotter uses incredible amounts of CPU & RAM但它没有答案,也没有真正解决为什么内存不会被释放。
关于在何处进行此操作的任何想法?在此先感谢您,如果我可以提供更多信息,请告诉我。
最佳答案
虽然我无法找到解决这个特定问题的方法,但我能够通过仅在 ScrollView 停止时调用 map 快照程序来解决它 - 然后它会抓取所有可见的单元格并仅加载这些单元格。这样,它可以最大限度地减少对此 API 的调用次数并防止内存问题,而不是在您通过 cellForRow
方法向下滚动列表时不断调用它。
关于ios - MKMapSnapshotter 内存崩溃 - UITableView 中的多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38250875/
我正在使用 MKMapSnapshotter 创建 MKMapView 的快照。这非常有效: let centerCoordinate = CLLocationCoordinate2DMake(-33
我有一个应用程序应该在后台获取对象并使用它们的位置数据为它们生成 map 快照。我自然而然地尝试了 MKMapSnapshotter。 事实证明(在对黑色 map 快照感到困惑数周之后)这个工具似乎只
我的 awakeWithContext 中有一个正在运行的 MKMapSnapshotter,我想为我的 imageView 设置它的图像。 问题是,MKMapSnapshotter 速度太慢,无法设
我正在使用 MKMapSnapshotter 创建 map 的屏幕截图,然后将其显示在 UIImageView 中。 let imageView = UIImageView() imageView.f
在连接到 Apple Watch 的真实 iPhone 上测试我的“ watch 应用程序”/iOS 应用程序 watch 扩展时,我遇到了 MKSnapshotter 的一些重大问题! 在我的一个接
我创建图钉图像的代码如下: MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init]; options.region =
我使用以下函数在 MKMapView 的 UIImage 快照上绘制折线。该功能有效,但对我来说太慢了。有什么办法可以加快速度吗? func drawLineOnImageFromLocations(
是否有任何原因导致 MKMapSnapshotter 的 startWithCompletionHandler 方法上的完成处理程序不会被回调? (甚至没有错误!!) 我没有做任何花哨的事情,只是抓取
我正在使用 MKMapSnapshotter 创建一个小型 MKMapView 的 UIImage 屏幕截图(并存储以备后用)。但我注意到的一件事是它从快照中删除了“合法”标签。 Here答案是删除“
我们有一个 iOS 应用程序,它有一个 UITableView,其中包含在单元格出现时生成的 map 快照。我们使用的示例列表只是显示基于模型类中提供的纬度/经度的 map 快照。我开始注意到内存崩溃
我对 MKMapSnapshotter 有疑问。我目前有两个 View ,一个带有 UIButton,显示 UIActivityViewController,另一个带有 MKMapView,显示当前用
自 iOS 13 起,此代码返回黑色图像。任何想法? 我还记录了这些警告: InfoLog FlyoverNightShader: WARNING: 0:29: Overflow in implici
我正在尝试在 MKMapSnapshotter 中绘制一个 MKCircleRenderer。 所以我需要的是: 所以我有: 我的代码: + (void)renderMapRegion:(MKCoor
我正在尝试使用新的 iOS7 MKMapSnapshotter 生成静态 map 图像。每当我的应用程序需要 map 时,我都会调用以下命令: MKMapSnapshotter *snapshotte
我认为 iOS 7 的 MKMapSnapshotter 将是拍摄 MKMapView 快照的简单方法,好处是您可以在不将 map 加载到 View 中的情况下执行此操作.尽管添加图钉和叠加层似乎需要
我正在自己学习 Swift 3,我当前的学习项目涉及允许用户拍摄照片并获取固定当前位置的 map 快照。 我依赖 this answer从 2015 年 8 月和 this answer从 2016
我有一个 UITableView,它可能包含大量单元格,在某些单元格中,我想要一个 UIImageView 来显示一个位置的 map ,其中的坐标仅在运行时已知。 我希望表格 View 能够平滑滚动,
我想在 UITableViewCells 中显示 mapView, 所以我实际上写了这段代码 class DataPointTableCell: UITableViewCell { @IBOu
我有一个奇怪的问题:我像往常一样使用 openParentApplication:reply: 调用父应用程序。 使用异步 NSURLRequests 从 Internet 获取一些数据的工作做得很好
我正在开发适用于 MKMapSnapshotter API 的应用。 它制作具有所需区域的 map 快照。 它的代码从前台应用程序状态和主线程调用,如下所示: MKMapSnapshotOptions
我是一名优秀的程序员,十分优秀!