我正在使用GoogleMaps 2.0.1我必须在其tap上显示自定义弹出窗口或自定义标记窗口。它应如下所示:
https://www.instagram.com/instagram/media/
这是我的自定义标记类的样子:
import UIKit
class MapPopUp: UIView {
@IBOutlet weak var lblName : UILabel!
@IBOutlet weak var lblDesc : UILabel!
@IBOutlet weak var btnClose : UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
var nibContents = NSBundle.mainBundle().loadNibNamed("MapPopUp", owner: self, options: nil)
self.addSubview(nibContents[0] as! UIView)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func didMoveToSuperview() {
guard superview != nil else {
return
}
self.superview!.autoresizesSubviews = false
}
}
这些是我的谷歌地图代表
func mapView(mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let vc = MapPopUp(frame: CGRectMake(0, 0, 310, 70))
vc.lblName.text = "N/A"
vc.lblDesc.text = "N/A"
vc.btnClose.addTarget(self,action:#selector(MapVC.closeAction(_:)),
forControlEvents:.TouchUpInside)
if let dict = marker.userData as? NSDictionary
{
if let strName = dict.objectForKey("name") as? String
{
vc.lblName.text = strName
}
if let strDesc = dict.objectForKey("description") as? String
{
vc.lblDesc.text = strDesc
}
}
vc.layoutIfNeeded()
vc.layoutSubviews()
return vc
}
func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {
var point = mapView.projection.pointForCoordinate(marker.position)
point.x = point.x + 100
let vancouverCam = GMSCameraUpdate.setTarget(marker.position)
mapView.animateWithCameraUpdate(vancouverCam)
self.mapView.selectedMarker = marker
return true
}
func mapView(mapView: GMSMapView, didTapInfoWindowOfMarker marker: GMSMarker)
{
self.mapView.selectedMarker = nil
}
Isuue在点击标记后,它显示正确的标记信息窗口,但在谷歌地图卡住后,它没有再次隐藏标记信息窗口。
先谢谢!!