答案 0 :(得分:4)
我的应用程序遇到了这样的问题。
在ViewController.swift中:
class ViewController: GMSMapViewDelegate {
func mapView(_ mapView: GMSMapView, markerInfoContents marker: GMSMarker) -> UIView? {
let placeMarker = marker as! PlaceMarker
if let infoView = UIView.viewFromNibName("MarkerInfoView") as? MarkerInfoView {
infoView.nameLabel.text = placeMarker.place.name
if let photo = placeMarker.place.photo {
infoView.placePhoto.image = photo
} else {
infoView.placePhoto.image = UIImage(named: "generic")
}
return infoView
} else {
return nil
}
}
}
2.然后创建一个UIView类:
import UIKit
class MarkerInfoView: UIView {
@IBOutlet weak var placePhoto: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
}
答案 1 :(得分:0)
为您的 public class XYZClass
{
public string Name { get; set; }
}
public class Tests
{
public void NormalBehavior()
{
var @ref = new WeakReference<XYZClass>(new XYZClass { Name = "bleh" });
GC.Collect();
GC.WaitForPendingFinalizers();
XYZClass t;
@ref.TryGetTarget(out t);
Console.WriteLine(t == null); //outputs true
}
public void WeirdBehavior()
{
var @ref = new WeakReference<XYZClass>(new XYZClass { Name = "bleh" });
GC.Collect();
GC.WaitForPendingFinalizers();
XYZClass t;
@ref.TryGetTarget(out t);
Console.WriteLine(t == null); //outputs false
Console.WriteLine(t?.Name == null); //outputs false
}
}
定义委托,并在您的委托中实施此功能:
func mapView(_ mapView:GMSMapView,markerInfoWindow marker:GMSMarker) - &gt; UIView的? { }
您可以在此函数内以编程方式创建视图,也可以通过nib文件创建视图。
<强>更新强>
不要忘记更改标记的infoWindowAnchor: https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_marker.html#a6668957ca7b6857355ee6cd9ab944a92