我正在研究一个项目,我想要在Google地图上撼动标记。 我正在使用自定义标记图标在地图上表示。像一个人的头在摇晃。 我不知道如何去做和搜索很多,但没有找到任何解决方案。我想在iOS中撼动Google地图标记Swift
回答
你可以添加一个CAKeyframeAnimation
或CABasicAnimation
到你的marker.iconView!.layer
我们添加一个比我们的UIImageView框架大的UIView,那么我们需要调整锚点你的UIImageView的点在垂直和水平居中的底部,这将成为我们动画中的枢轴点,我们的动画将是一个在-30到30级的Z平面上的旋转动画,以实现所需的动画。这是最简单的方式来做到这一点,但你也可以自定义一个类,并作出了很多其他的事情
let marker = GMSMarker(position: CLLocationCoordinate2D(latitude: 22.404963, longitude: -79.961755))
//we need a bigger UIView to avoid the clip problem with the UIImageView
marker.iconView = UIView(frame: CGRect(x: 0, y: 0, width: 60, height: 40))
let imageView = UIImageView(frame: CGRect(x: (marker.iconView?.frame.width)!/2 - 14, y: (marker.iconView?.frame.height)! - 36, width: 28, height: 36))
imageView.contentMode = .scaleAspectFit
imageView.image = UIImage(named: "iconomapa")
marker.iconView?.addSubview(imageView)
imageView.layer.anchorPoint = CGPoint(x: 0.5, y: 1.0) //we need adjust anchor point to achieve the desired behavior
imageView.layer.frame = CGRect(x: (marker.iconView?.frame.width)!/2 - 14, y: (marker.iconView?.frame.height)! - 36, width: 28, height: 36) //we need adjust the layer frame
let animation = CAKeyframeAnimation()
animation.keyPath = "transform.rotation.z"
animation.values = [ 0, -30 * .pi/180.0, 30 * .pi/180.0 , 0]
animation.keyTimes = [0, 0.33 , 0.66 , 1]
animation.duration = 1;
animation.isAdditive = false;
animation.isRemovedOnCompletion = true
animation.repeatCount = .infinity
marker.iconView!.subviews[0].layer.add(animation, forKey: "shakeAnimation")
marker.map = self.mapView
这里是如何看起来
希望这有助于
谢谢@Reinier 但我得到无 marker.iconView!.layer.add(动画,forKey:“shakeAnimation”) –
@ParthDhorda我的答案已更新,您需要用您的替换iconomapa标记图像名称 –
我想引脚应该保持在相同的纬度和长度,但头部应该晃动不是整个针 谢谢 –
您可以使用标记属性来旋转你的标记,
marker.rotation = (you_angle_in_degree) * M_PI/180.0f;
// convert degree to radian
的水平摇晃动画后的一段时间间隔改变度旋转,你可以使用定时器,你可以得到,
// create a timer
timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
func timerAction() {
// Place you aniamtion logic here ,
// every 0.5 second change the rotation of your maker
}
- 1. iOS Google地图标记拖动动画
- 2. 我想在google地图上用标记显示活动日期
- 3. Google地图标记动画
- 4. 如何在Google地图上标注地图标记ios
- 5. 在Google地图上移动Google地图标记自动完成
- 6. 我的Google地图标记在哪里?
- 7. ios Swift Google地图sdk不能在iPhone6s +
- 8. Google地图标记
- 9. iOS上的Google地图标记反弹动画? [Objective-c]
- 10. 围绕Google地图标记的脉冲环动画iOS
- 11. 在Google地图中标记街道
- 12. 在Google地图中放置标记
- 13. 在Google地图中标记点击
- 14. 在Google地图中获取标记ID
- 15. 自动刷新Google地图标记
- 16. Android Google地图标记运动问题
- 17. 向Google地图动态添加标记
- 18. 使用Google地图SDK中心地图和添加标记子视图(Swift)
- 19. Swift Detecting在Google地图上按下哪个标记
- 20. Google地图标记群集
- 21. android + Google地图标记
- 22. Google地图API标记
- 23. Google地图标记距离?
- 24. 更改Google地图标记
- 25. Google地图标记事件
- 26. Google地图连接标记
- 27. 隐藏Google地图标记
- 28. Google地图中的中心标记
- 29. 在Google地图中显示可见标记,许多标记
- 30. 试图在动态地图中创建多个Google地图标记
你需要动画sh是水平的还是垂直的? –
你可以使用标记的旋转属性, – Dhiru
你也可以这样做 https://stackoverflow.com/questions/40543095/bounce-animation-on-google-map-marker-in-ios-objective-c – Dhiru