swift GMSMap markerInfoWindow 动画显示

swift GMSMap markerInfoWindow show by animation

我想在点击标记从红色变为蓝色时显示我的 markInfoWindow

我试过了

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    
    let windowInfoView: UIView = {
        let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 130, height: 55))
        view.backgroundColor = UIColor.white
        view.layer.cornerRadius = view.frame.height/3
        
        return view
    }()
    

    let anim : CABasicAnimation = CABasicAnimation(keyPath: "backgroundColor")
    anim.fromValue = UIColor.yellow.cgColor
    anim.toValue = UIColor.red.cgColor
    anim.duration = 2.0

    windowInfoView.layer.add(anim, forKey: "backgroundColor")
    
    return windowInfoView

但是当我点击标记时,它直接显示黄色 window,没有在 2 秒内从黄色显示为红色 谢谢

我解决了这个问题

我创建了一个自定义视图并在委托中添加了视图

func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
    
    self.view.addSubview(self.infoWindow)
    
    UIView.transition(with: self.view, duration: 1, options: [.transitionCrossDissolve], animations: {
        self.infoWindow.alpha = 1
    }, completion: nil)
    
    return false
}

无法在 markerInfoWindow 中自定义视图,因为它 return 一个 UIView。