我有一个谷歌地图,我为我的标记创建了一个自定义信息窗口。我在窗口上放了几个按钮,但我终生无法与它们互动。这是我的自定义视图:
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")
}*/
}
这是在视图控制器中返回视图的方法:
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
}
我尝试了很多东西来尝试与这个视图交互,包括在堆栈中移动视图、移动层等。以前有人遇到过这个问题吗?知道我做错了什么。我注释掉的东西主要是我试图破解它。