- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在 UITableViewCells
中显示 mapView,
所以我实际上写了这段代码
class DataPointTableCell: UITableViewCell {
@IBOutlet weak var mapView: MKMapView!
func addAnnotaionToMapView(_ coordinates: Coordinate) {
removePreviousCoordinate()
let viewCoorindate = CLLocationCoordinate2D(latitude: coordinates.latitude, longitude: coordinates.longitude)
let annotation = MKPointAnnotation()
annotation.coordinate = viewCoorindate
mapView.addAnnotation(annotation)
// animate is turned to false on purpose.
mapView.animateToPoint(viewCoorindate, animated: false)
}
private func removePreviousCoordinate() {
let annotations = self.mapView.annotations
self.mapView.removeAnnotations(annotations)
}
}
这种方法的问题是它为 mapView 位置设置动画,然后在它对单元格进行双端队列时添加标记。
我采用了另一种方法,即使用 MKMapSnapshotter
private func setMapImage() {
let rect = self.mapImageView.bounds
let mapSnapshotOptions = MKMapSnapshotter.Options()
// Set the region of the map that is rendered.
let needleLocation = CLLocationCoordinate2DMake(15.4952364, 73.8343293)
let region = MKCoordinateRegion(center: needleLocation, latitudinalMeters: 1000, longitudinalMeters: 1000)
mapSnapshotOptions.region = region
// Set the scale of the image. We'll just use the scale of the current device, which is 2x scale on Retina screens.
mapSnapshotOptions.scale = UIScreen.main.scale
// Set the size of the image output.
mapSnapshotOptions.size = CGSize(width: 300, height: 300)
// Show buildings and Points of Interest on the snapshot
mapSnapshotOptions.showsBuildings = true
mapSnapshotOptions.showsPointsOfInterest = false
let snapshot = MKMapSnapshotter(options: mapSnapshotOptions)
snapshot.start { snapshot, error in
guard let snapshot = snapshot, error == nil else {
print("\(error!.localizedDescription)")
return
}
UIGraphicsBeginImageContextWithOptions(mapSnapshotOptions.size, true, 0)
snapshot.image.draw(at: .zero)
let pinView = MKPinAnnotationView(annotation: nil, reuseIdentifier: nil)
let pinImage = pinView.image
var point = snapshot.point(for: needleLocation)
if rect.contains(point) {
let pinCenterOffset = pinView.centerOffset
point.x -= pinView.bounds.size.width / 2
point.y -= pinView.bounds.size.height / 2
point.x += pinCenterOffset.x
point.y += pinCenterOffset.y
pinImage?.draw(at: point)
}
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
DispatchQueue.main.async {
self.mapImageView.image = image
}
}
}
这工作正常,但我无法缓存基于任何内容的图像。
所以我想要的帮助是如何使用 SDWebimage 下载和缓存 mapImage .
最佳答案
首先为你的手机添加一个唯一的键
var youUniqueCellKey = "Key"
然后在 setMapImage
中首先检查图像是否已经缓存并将其分配给您的 mapImageView
private func setMapImage() {
if let image = SDImageCache.shared().imageFromCache(forKey: youUniqueCellKey) {
self.mapImageView.image = image
} else {
// Add your rest of your code here
// At the end
var imageToStore = UIImage() // Your mapImage
SDImageCache.shared().store(imageToStore, forKey: youUniqueCellKey, completion: nil)
}
}
关于swift - 使用 SDWebimage 下载并缓存 MKMapSnapshotter 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55719933/
我正在使用iPhone应用程序。在这个应用程序中,我使用了许多图像,我需要将这些图像存储在高速缓存中。为此,我发现SDWebImage是正确的框架,但无法在我的iPhone项目中包括此框架。谁能建议我
我使用 SDWebImage 将图像下载到我的 UITableView 中: [cell.imageView setImageWithURL:[NSURL URLWithString:tempPhot
如何使用 UIImageView 在 SDWebImage 占位符中设置事件指示器 最佳答案 Swift 5 和 SDWebImage 5-beta //pod file pod 'SDWebImag
所以首先,我发现了这个: SDWebImage process images before caching 这有帮助,但我真的想使用SDWebImage,有没有办法在完成之前通过类外部的方法处理图像?
我在应用程序中使用SDWebImage从网络加载和缓存图像。它的工作原理就像是一种魅力,但是唯一的问题是,每当我退出应用程序时,即使是暂时退出,图像缓存也会被清除,所有图像都必须再次下载。 Inter
我正在使用 SDWebImage 将图像从服务器获取到我在 IOS 中的表格 View 应用程序。 但问题是,当我在表格 View 中向下滚动而不是等待图像加载时,将下载的图像放在表格 View 的前
我正在尝试使用 SDWebImage 来缓存从网络检索的图像。图像一直缓存到内存中。我已经看到默认保存到磁盘的文档。 Everything will be handled for you, from
我有一个带有背景图像的按钮,我使用 SDWebImage 下载该按钮。我想保持高度不变,并通过保持纵横比而不剪切图像来改变宽度。只是恒定的高度和动态宽度。这里出了什么问题? //CODE FROM F
我使用 SDWebImage pod 进行下载并显示来自 json 的图像,它运行良好,但我有一个大问题。 我正在使用collectionView,当加载单元格时,某些单元格显示错误的图像。我搜索了它
我一定是在做一些愚蠢的事情,但是 SDWebImage 永远不会执行以下的完成处理程序: episodeImageView?.sd_setImage(with: url, completed: { [
我正在使用 SDWebImage 库。当我使用 iPhone 时它工作正常,但当我使用模拟器编译时它不起作用。我收到此错误: Undefined symbols for architecture
我尝试了 100 多种使用 SDWebImage 制作图像动画的方法,但总是失败。我理解使用 block 好吗?我有 IBOutlet 属性图像名称 images1。我制作了数组来存储值并为 3 个图
我正在使用 SDWebImage 框架下载 iPhone 游戏中的个人资料图像。 [cell.playerImage setImageWithURL:url placeholderImage: Def
我在 UICollectionView 和 UITableView 中使用 SDWebImage。在这两种情况下,当行数很高时,内存使用率有时会非常高,我会收到内存警告。 以下是我的头像: 你看,有时
我正在使用 SDWebImage 库来缓存 UICollectionView 的图像,该图像是从 url 下载的,每次发送所有请求但只下载两个图像。有谁知道原因吗???提前致谢。 代码是: SDWeb
美好的一天! 从网络下载全尺寸图像时,我使用这两个库。 代码: -(void)viewDidAppear:(BOOL)animated { dispatch_async(dispatch_ge
是否可以使用SDWebImage下载AES加密图片?如果是这样,我在哪里可以访问下载的数据,手动解密它们? 最佳答案 不幸的是,无法使用 SDWebImage 下载加密图像。我只是看了他们的类图,没有
我正面临这个问题,下面是代码。它第一次显示错误,然后没有完成 block 调用。 [self.comicsImage setImageWithURL:[NSURL URLWithString:self
我检查了 NSBundle,但找不到 SDWebImage 保存图像的缓存。缓存是否启用(见下面的代码)?根据Docs它进行缓存管理。 如文档中所示: Just #import the UIImage
这个问题可能很奇怪,但它正在发生,而我却不明白。 我刚刚从 https://github.com/rs/SDWebImage 下载了代码并尝试运行示例项目。 它正在构建成功,但没有运行。为什么? 提前
我是一名优秀的程序员,十分优秀!