我正在研究一個項目,我想要在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地圖中刪除標記iOS
- 4. Google地圖標記動畫
- 5. 在Google地圖上移動Google地圖標記自動完成
- 6. 如何在Google地圖上標註地圖標記ios
- 7. 自定義谷歌地圖標記圖標圖像在swift ios
- 8. 我想使用swift在ios中顯示多層室內地圖
- 9. 我的Google地圖標記在哪裏?
- 10. 在Google地圖上移動標記
- 11. ios Swift Google地圖sdk不能在iPhone6s +
- 12. Google地圖標記
- 13. Google地圖標記的動態圖像
- 14. 我的Google標記未顯示在Google地圖中
- 15. iOS上的Google地圖標記反彈動畫? [Objective-c]
- 16. 圍繞Google地圖標記的脈衝環動畫iOS
- 17. 使用Google地圖SDK中心地圖和添加標記子視圖(Swift)
- 18. 在Google地圖中提醒標記值
- 19. 在Google地圖中標記街道
- 20. 在Google地圖中標記點擊
- 21. 在Google地圖中獲取標記ID
- 22. 在Google地圖中放置標記
- 23. 在Google地圖中放置標記
- 24. Google地圖標記動畫IE問題
- 25. Android Google地圖標記運動問題
- 26. 自動刷新Google地圖標記
- 27. Google地圖標記脈衝動畫?
- 28. 向Google地圖動態添加標記
- 29. Swift Detecting在Google地圖上按下哪個標記
- 30. Google地圖上的繪圖標記JSON文件中的iOS
你需要動畫sh是水平的還是垂直的? –
你可以使用標記的旋轉屬性, – Dhiru
你也可以這樣做 https://stackoverflow.com/questions/40543095/bounce-animation-on-google-map-marker-in-ios-objective-c – Dhiru