简体   繁体   English

在MKAnnotation标注Swift上创建一个文本字段

[英]Create a textfield over MKAnnotation Callout Swift

I'd like to make an editable callout, and from a quick look it seems like the best way is to create a textfield over it in the view. 我想进行一个可编辑的标注,从快速的外观看,似乎最好的方法是在视图中创建一个文本框。 So, I was wondering how to get the CGPoint of an annotation so that I can use it in placing my CGRect of a textfield. 因此,我想知道如何获取注释的CGPoint,以便可以将其用于放置文本字段的CGRect。 This is the code I'm using to display an annotation at a tapped point, how would one do the reverse? 这是我用来在点击的位置显示注释的代码,怎么回事? If anyone suggests better ways to create an editable callout, I'm welcome to suggestions 如果有人建议更好的方法来创建可编辑的标注,欢迎提出建议

 var point:CGPoint = gestureRecognizer.locationInView(self.Map)

  EventLoc = self.Map.convertPoint(point, toCoordinateFromView: self.Map)

I'm not too familiar with Swift yet, but independent from the language, MKMapView has a method convertCoordinate:toPointToView: which you can use to convert a CLLocationCoordinate2D to a CGPoint . 我对Swift不太熟悉,但与语言无关, MKMapView有一个convertCoordinate:toPointToView:方法,可用于将CLLocationCoordinate2D转换为CGPoint

EDIT 编辑

From the MKMapView reference : MKMapView参考

Converts a map coordinate to a point in the specified view. 将地图坐标转换为指定视图中的点。

So in your case the last argument should be your map view: 因此,在您的情况下,最后一个参数应该是您的地图视图:

The view in whose coordinate system you want to locate the specified map coordinate. 要在其坐标系中找到指定地图坐标的视图。 If this parameter is nil, the returned point is specified in the window's coordinate system. 如果此参数为nil,则在窗口的坐标系中指定返回的点。 If view is not nil, it must belong to the same window as the map view. 如果view不为nil,则它必须与地图视图属于同一窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM