xcode - Google Maps Swift 中的脉动标记动画

标签 xcode swift google-maps cllocation markers

我正在使用 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/

相关文章:

C++ EXC_BAD_ACCESS(代码=1 访问=0x0)

jquery - 谷歌地图,基于 Zoom 的比例圆

javascript - Google maps V3 dragend 监听器将所有标记添加回 map

ios - 在 iOS Playground 应用程序中将 View 置于 View Controller 内居中

ios - 显示键盘会导致包含事件文本字段的单元格行隐藏在其节页脚下方

ios - 将行中间与 UITableView 中间对齐

android - 加载 map 失败。在 fragment 上联系 Google 服务器时出错

xcode - 为什么 UIButton 在模拟器中这么大?

xcode - 使用 NSuserdefaults 在 swift 中设置图像

ios - 如何在 Storyboard上抑制 Xcode 5 中的约束和布局警告?