已达到纹理图集最大数量,无法为 iconView 分配更多

问题描述 投票:0回答:1

我的问题与使用Google Maps“达到纹理图集的最大数量,无法分配更多”完全一样,但我使用的是Gif图像,所以我正在使用标记的iconView

而不是图标。这是代码:

let markerGifView = UIImageView(image: UIImage.gifImageWithName("name-of-gif")) markerGifView.frame = CGRect(x: 0, y: 0, width: 100, height: 142) for i in 0..<latValues.count { var marker: GMSMarker? let position = CLLocationCoordinate2D(latitude: latValues[i], longitude: lonValues[i]) marker = GMSMarker(position: position) marker?.userData = data marker?.map = self.mapView marker?.iconView = self.markerGifView }

为了提供 Gif 支持,我使用了这个:

https://gist.github.com/thechaudharysab/b4f9884dcff20c3b8aeb5b4c1fd1756e

当我滚动地图时,运行应用程序几秒钟后会出现此错误。

((null)) was false: 达到纹理图集最大数量,不能 分配更多。

swift google-maps-markers gmsmapview
1个回答
0
投票
这是根据我的评论建议的解决方案

func addMarkers() { let currentMarkers = itemsMarkers var markersToDelete = itemsMarkers var markerIcons: [String: UIImage] = [:] markerIcons = getMarkerIcons(items: items) itemsMarkers = [] items?.enumerated().forEach { (offset, item) in guard let position = item.coordinate else { return } if let marker = currentMarkers.first(where: { ($0.userData as? MyItem)?.id == item.id }) { var key = item.properties.imageRef if item.hasFailure { key += "-fail" } else { key += "-ok" } marker.icon = markerIcons[key] marker.title = item.name marker.userData = item marker.position = position markersToDelete.removeAll(where: { ($0.userData as? MyItem)?.id == item.id }) itemMarkers.append(marker) } else { let marker = GMSMarker(position: position) var key = item.properties.imageRef if item.hasFailure { key += "-fail" } else { key += "-ok" } marker.icon = markerIcons[key] marker.title = item.name marker.userData = item marker.zIndex = Int32(offset) marker.map = mapView itemMarkers.append(marker) } } markersToDelete.forEach { $0.map = nil } } private func getMarkerIcons(items: [MyItem]?) -> [String: UIImage] { var markerIcons: [String: UIImage] = [:] guard let items else { return markerIcons } items.forEach { item in var key = item.properties.imageRef if item.hasFailure { key += "-fail" } else { key += "-ok" } if markerIcons[key] == nil { let markerView = ItemMarkerView.fromNib markerView.item = item markerIcons[key] = markerView.asImage() } } return markerIcons }
    
© www.soinside.com 2019 - 2024. All rights reserved.