【发布时间】:2014-11-19 12:36:12
【问题描述】:
我正在使用 swift 创建一个应用程序。在我的一个 ViewController 中,我有一个以编程方式创建的 GMSMapView。我希望用户能够在点击地图时触发操作。
我做了什么:
import UIKit
class MapViewController: UIViewController, GMSMapViewDelegate {
let mapView = GMSMapView()
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
mapView.settings.scrollGestures = false
mapView.frame = CGRectMake(0, 65, 375, 555)
view.addSubview(mapView)
var tap = UITapGestureRecognizer(target: self, action: "tap:")
mapView.addGestureRecognizer(tap)
}
func tap(recogniser:UITapGestureRecognizer)->Void{
println("it works")
}
}
我试图覆盖 touchesBegan,但没有奏效。我试图插入 mapView.userInteractionEnabled = true,没用...
有什么想法吗?
【问题讨论】:
-
我在你的代码中添加了一行代码 mapView.isUserInteractionEnabled = true 但还是不行。
标签: ios swift uitapgesturerecognizer gmsmapview