移动自定义窗口的位置Google Map Swift

时间:2019-02-05 00:04:28

标签: ios swift google-maps

我不知道如何根据标记更改窗口的位置。当我更改x或y的值时,什么也没发生。

这是我的代码:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    let sarahBlue = UIColor(red: 33, green: 48, blue: 78, a: 1)

    let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 70))
    view.backgroundColor = sarahBlue
    view.layer.cornerRadius = 6

    if let pointName = marker.title {

        let imgVw : UIImageView = {
            let iv = UIImageView()
            iv.image = UIImage(named: "La maison des tramwayen1")
            iv.translatesAutoresizingMaskIntoConstraints = false
            return iv
        }()

        let lbl : UILabel = {
            let lbl = UILabel()

            let yellowSarah = UIColor(red: 242, green: 191, blue: 5, a: 1)
            lbl.textColor = yellowSarah
            lbl.font = UIFont(name: "Arial Rounded MT Bold", size: 10)
            lbl.textAlignment = NSTextAlignment.center
            lbl.numberOfLines = 0
            lbl.sizeToFit()
            lbl.text = marker.title
            lbl.translatesAutoresizingMaskIntoConstraints = false
            return lbl
        }()

        var pointNameWithoutAcc : String = pointName.replacingOccurrences(of: "é", with: "e")
        pointNameWithoutAcc = pointNameWithoutAcc.replacingOccurrences(of: "è", with: "e")
        view.addSubview(imgVw)
        imgVw.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 5).isActive = true
        imgVw.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -5).isActive = true
        imgVw.topAnchor.constraint(equalTo: view.topAnchor, constant: 5).isActive = true
        imgVw.widthAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1).isActive = true
        let imageName = pointNameWithoutAcc + "0" + "SL"
        imgVw.image = UIImage(named: imageName)

        view.addSubview(lbl)
        lbl.leftAnchor.constraint(equalTo: imgVw.rightAnchor, constant: 5).isActive = true
        lbl.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0).isActive = true
        lbl.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -20).isActive = true
    }


    return view
}

当我单击一个标记并将自定义窗口添加到标记上方时,我的代码就会执行。

0 个答案:

没有答案