我正在使用 Swift 的 GMaps SDK,我的目标是用脉动效果等动画类型替换标准标记。我试着玩图层但没有运气。关于如何在我的标记图像上添加动画效果有什么建议吗?
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
最佳答案
您可以通过在其状态下绘制图像来实现。例如,我画了一个闹钟脉动图像,一条线亮起,两条线亮起,等等。然后你为这些图像制作动画。
像这样定义动画图像、单个图像和图像数组:
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)
当您想在 map 上绘制动画图像并看到脉动效果时,请使用通常的 GMSMapView 和 GMSMarker 代码,例如:
let marker = GMSMarker()
let markerView = UIImageView(image: animatedImage)
marker.position = CLLocationCoordinate2D(latitude: userLat, longitude: userLng)
marker.iconView = markerView
marker.map = mapView
关于xcode - Google Maps Swift 中的脉动标记动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37408831/