我正在使用GMaps SDK for Swift,我的目标是用动画类型替换标准标记,如脉动效果。我尝试玩图层但没有运气。有什么建议我如何在我的标记图像上添加动画效果?
let parkingSpotsPosition = CLLocationCoordinate2D(latitude: self.SpotLocationLatitudes.last!, longitude: self.SpotLocationLongitudes.last!)
let marker = GMSMarker(position: parkingSpotsPosition)
marker.title = self.SpotNames.last
//marker.icon = GMSMarker.markerImageWithColor(UIColor.greenColor())
marker.icon = UIImage(named: "parking-location")
marker.map = self.gMapsView
答案 0 :(得分:1)
您可以通过在其状态下绘制图像来完成此操作。例如,我用一条线照亮,两条线点亮等绘制的警报脉动图像。然后,您可以为这些图像设置动画。
定义animatedImage,单个图像和图像数组,如下所示:
var animatedImage: UIImage!
var image1: UIImage!
var image2: UIImage!
var image3: UIImage!
var image4: UIImage!
var images: [UIImage]!
像viewDidLoad这样的地方,请按照您选择的持续时间进行设置。我使用Sketch App绘制单个图像。
image1 = UIImage(named: "MarkerTrouble1.png")
image2 = UIImage(named: "MarkerTrouble2.png")
image3 = UIImage(named: "MarkerTrouble3.png")
image4 = UIImage(named: "MarkerTrouble4.png")
images = [image1, image2, image3, image4]
animatedImage = UIImage.animatedImage(with: images, duration: 0.8)
当您想在地图上绘制动画图像并查看脉动效果时,请使用常用的GMSMapView和GMSMarker代码,例如:
let marker = GMSMarker()
let markerView = UIImageView(image: animatedImage)
marker.position = CLLocationCoordinate2D(latitude: userLat, longitude: userLng)
marker.iconView = markerView
marker.map = mapView