1

我有一个谷歌地图,我为我的标记创建了一个自定义信息窗口。我在窗口上放了几个按钮,但我终生无法与它们互动。这是我的自定义视图:

class MarkerWindowView: UIView, UIGestureRecognizerDelegate {

//@IBOutlet weak var thumbNail: UIImageView!
@IBOutlet weak var userName: UILabel!
@IBOutlet weak var videoLocation: UILabel!
@IBOutlet weak var tags: UILabel!


override func awakeFromNib() {
println("awake From Nib")
    self.userInteractionEnabled = true
    print(self.userInteractionEnabled)
    /*let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTap:"))
    recognizer.delegate = self
    /*for test in layer.sublayers {
        println(test)
    }*/*/
}

@IBAction func playVideoPressed(sender: AnyObject) {
    println("play video")
}
@IBAction func markerWindowViewWasTapped(sender: UITapGestureRecognizer) {
    println("playvideo")
}
/*func handleTap(recognizer: UITapGestureRecognizer) {
    println("tapped")
}*/

}

这是在视图控制器中返回视图的方法:

func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
    println("markeInfoWindow")
    var newView = NSBundle.mainBundle().loadNibNamed("MarkerWindowView", owner: self, options: nil).first! as! MarkerWindowView
    //println(newView.description)
    newView.userName.text = "Kazuma"
    newView.videoLocation.text = "Harvard"
    newView.tags.text = "Kazuma is crazy"
    //view.bringSubviewToFront(newView)
    //view.insertSubview(newView, atIndex: 0)
    //newView.userInteractionEnabled = true
    /*for subView in self.view.subviews {
        println(subView)
    }*/
    //view.bringSubviewToFront(newView)
    return newView
}

我尝试了很多东西来尝试与这个视图交互,包括在堆栈中移动视图、移动层等。以前有人遇到过这个问题吗?知道我做错了什么。我注释掉的东西主要是我试图破解它。

4

1 回答 1

1

自定义信息窗口呈现为 UIImage,因此您无法与上面的任何内容进行交互。我遇到了类似的问题,最终使整个窗口成为一个“按钮”,导致嵌入 segue 将视图推送到地图上,为我提供了详细信息(想想 Yelp 应用程序风格)。

My info window was contained in a separate .xib. Here is some code in my GMSMapViewDelegate:

func mapView(mapView: GMSMapView!, didTapInfoWindowOfMarker marker: GMSMarker!)
{
    ShowDetailView(mapMarkerManager!.GetMapMarker(marker)!)
}

func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView!
{
    let markerInfoWindow = UINib(nibName: "MarkerInfoPopup", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! MarkerInfoPopup

    markerInfoWindow.setValues(mapMarkerManager!.GetMapMarker(marker)!)
    return markerInfoWindow
}

private func ShowDetailView(mapMarker: MapMarker)
{
    delegate!.SetMapMarker(self, mapMarker: mapMarker)

    self.view.bringSubviewToFront(mapDetailView)
    mapDetailView.hidden = false

    mapView.hidden = true
    BackToMapButton.hidden = false
}

(mapMarker is more or less a GMSMarker wrapper. It does other stuff but is not important in this context)

I know this isn't exactly what you wanted, but unfortunately there aren't many options when using Google Maps' built in markerInfoWindow/didTapInfoWindowOfMarker.

Reference: https://developers.google.com/maps/documentation/ios-sdk/marker?hl=en#info_windows

"Note: The info window is rendered as an image each time it is displayed on the map. This means that any changes to its properties while it is active will not be immediately visible. The contents of the info window will be refreshed the next time that it is displayed."

于 2015-09-21T21:17:38.900 回答