Map中的自定义信息窗口互动

Map中的自定义信息窗口互动

本文介绍了无法与Google Map中的自定义信息窗口互动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张Google地图,并且为标记创建了一个自定义信息窗口.我在窗口上放了几个按钮,但是我无法与他们互动.这是我的自定义视图:

I have a google map and I've created a custom info window for my markers. I've put a couple buttons on the window, but I can't interact with them for the life of me. Here is my custom view:

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")
}*/

}

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

and here is the method that returns the view in the view controller:

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
}

我已经尝试了很多方法来尝试与此视图进行交互,包括在堆栈中移动视图,移动图层等.以前有人遇到过此问题吗?知道我在做什么错.我注释掉的内容大部分是我试图破解的内容.

I have tried a bunch of stuff to try to interact with this view including shifting views in the stack, moving layers etc. Has anyone had this problem before? Any idea what I'm doing wrong. The stuff I commented out is mostly me trying to hack it.

推荐答案

自定义信息窗口呈现为UIImage,因此您无法与其上的任何内容进行交互.我遇到了类似的问题,最终使整个窗口成为一个按钮",从而导致嵌入的按钮将视图推到地图上,从而为我提供了详细信息(请考虑使用Yelp应用程序样式).

A custom info window is rendered as an UIImage, so you cannot interact with anything on it. I had a similar problem, and ended up making the entire window one "button" that caused an embed segue to push a view over the map, giving me details (think Yelp app style).

我的信息窗口包含在单独的.xib中.这是我的GMSMapViewDelegate中的一些代码:

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或多或少是GMSMarker包装器.它可以做其他事情,但在此情况下并不重要)

我知道这并不是您真正想要的,但是不幸的是,使用内置在markerInfoWindow/didTapInfoWindowOfMarker中的Google Maps时没有太多选择.

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

参考: https://developers.google. com/maps/documentation/ios-sdk/marker?hl = zh-CN#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."

这篇关于无法与Google Map中的自定义信息窗口互动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:53