Google Maps iOS-自定义信息窗口按钮不起作用

时间:2018-09-03 21:21:33

标签: ios swift google-maps infowindow

我正在为标记创建一个自定义信息窗口,并且所有内容都可以正确显示,但是我的按钮目标未执行。

这是我的自定义视图:

import UIKit

class CustomInfoWindow: UIView {

    let nibName = "CustomInfoWindow"
    @IBOutlet var contentView: UIView!
    @IBOutlet weak var lblTitle: UILabel!
    @IBOutlet weak var lblContent: UILabel!
    @IBOutlet weak var myBtn: UIButton!


    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }

    private func commonInit() {
        Bundle.main.loadNibNamed(nibName, owner: self, options: nil)
        addSubview(contentView)
        contentView.frame = self.bounds
        contentView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
        contentView.layer.cornerRadius = 6
        myBtn.addTarget(self, action: #selector(self.onBtnPress), for: .touchUpInside)

    }

    @objc func onBtnPress() {
        print("Btn pressed")
    }
}

这是我创建视图的方式:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
        let view = CustomInfoWindow(frame: CGRect.init(x: 0, y: 0, width: 350, height: 300))
        // other setup stuff
        return view
    }

有人知道我在做什么错吗?

0 个答案:

没有答案