[英]iOS Google maps method UIView animate not working
因此,我想在地图上隐藏并显示一个按钮,以放大当前用户的位置。
基本上,当地图不再以用户的位置为中心时,该按钮将在刚被按下时显示和消失。
按下该按钮时动画消失,但调用该方法时不动画
我正在从Google地图的api委托中调用一个方法,该方法在地图每次移动时都会被调用。
这是我的代码:
func showUserLocation() {
mapView.isMyLocationEnabled = true
self.locationManager.startUpdatingLocation()
let userLocation = mapView.myLocation
if let loc = userLocation
{
centreMapOnLocation(location: loc)
if myLocationButton.alpha == 1 {
UIView.animate(withDuration: 0.4, animations: {
self.myLocationButton.alpha = 0
})
}
}
}
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
if myLocationButton.alpha == 0 {
UIView.animate(withDuration: 0.4, animations: {
self.myLocationButton.alpha = 1
})
}
}
当willMove
方法被调用时,它只是出现而没有动画。
在UIView.animate
块中添加以下行:
self.view.layoutIfNeeded()
view
是您要设置动画的按钮的包含视图。 这告诉视图在视图的动画周期内重绘。
尝试使用显示按钮
self.myLocationButton.isHidden = false
并隐藏按钮
self.myLocationButton.isHidden = true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.