Sid*_*tha 0 touchesbegan gmsmapview swift
我正在尝试为我的应用弹出一个弹出窗口。到目前为止,弹出窗口以固定的坐标弹出,我试图将其弹出到用户点击的位置。这就是我所拥有的:
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("touchesbegan")
for touch in touches{
//Handle touch
let location = touch.locationInView(self.view)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ColonyPopoverController") as! ColonyPopoverController
vc.modalPresentationStyle = .Popover
vc.preferredContentSize = CGSizeMake(200, 150)
if let popoverController = vc.popoverPresentationController {
popoverController.delegate = self
popoverController.sourceRect = CGRectMake(location.x, location.y, 20, 10)
popoverController.sourceView = self.view
self.presentViewController(vc, animated: true, completion: nil)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到当我点击模拟器时,打印语句永远不会打印。
我认为interaction并已multi-touch启用。我知道这种方法很好用,因为我也将其与Google Maps集成在一起,因此当我点击时,会出现一个google pin:
func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
Run Code Online (Sandbox Code Playgroud)
}
我也看到了打印报表。不知道我在这里想念的是什么。
超级视图和视图均启用了用户交互:
导致视图无法收到触摸的主要原因有三个:
它已userInteractionEnabled设置为false。显然,您已经验证了事实并非如此。
其他一些视图位于感兴趣的视图之上,并且正在接受触摸。请注意,子视图位于其父视图的顶部(在儿童覆盖的区域中),情节提要文档大纲中较低的视图位于大纲中较高的任何同级项的顶部。(在屏幕截图中,KittyMapper®位于“地图视图”的顶部,在它们重叠的任何区域中。)userInteractionEnabled如果您不希望顶视图接收触摸,则需要将其设置为false。
兴趣视图超出其父视图的范围。
命中测试以递归方式工作:窗口调用hitTest(_:withEvent:)其每个子级(从上到下的顺序),直到一个子级返回非nil为止。hitTest(_:withEvent:)如果pointInside(_:withEvent:)返回false,则立即返回nil ;否则,hitTest(_:withEvent:)调用hitTest(_:withEvent:)子项(从上到下的顺序),直到返回非nil为止;self如果没有子项报告命中,则返回。
因此,如果子项超出其父项的范围,则它是可见的(如果所有祖先都clipsToBounds设置为false),但永远不会收到触摸,因为其父项pointInside(_:withEvent:)会拒绝看似在子视图中的触摸。
通过使用Xcode的“调试视图层次结构”功能检查视图层次结构,您也许可以诊断出最后两种情况。
| 归档时间: |
|
| 查看次数: |
7682 次 |
| 最近记录: |