如果我添加新的自定义注释,然后单击按钮以弹出标注,或者单击地图上的任意位置,则不会发生任何事情。 如果我再次单击,一切正常... 有任何想法吗?我看过很多理论,但到目前为止还没有运气...
import urllib.parse as url_parse
url = rurl
news_link = url_parse.unquote(url).split("?u=")[1].split("?fbclid")[0]
print("here comes the news_link")
print(news_link)
import requests
final_link = requests.get(news_link)
print("here comes the final_link.url")
如果用长按识别器代替长按,则会显示标注,但长按会创建另一个注释...因此长按必须是正确的方法。但是我该如何解决这个问题,以便用户可以长按创建注释,然后点击一次以获取标注?
答案 0 :(得分:0)
所以,我经过整整三天的努力终于找到了解决方案……发生的是长按继续遮盖了所有其他手势。因此无法识别下一个拍子,只有第二个拍子。 修复非常简单,可以在选择器中进行如下修复:
@objc func createNewAnnotation(_ sender: UIGestureRecognizer) {
let touchPoint = sender.location(in: self.mapView)
let coordinates = mapView.convert(touchPoint, toCoordinateFrom: self.mapView)
let heldPoint = MKPointAnnotation()
heldPoint.coordinate = coordinates
if (sender.state == .began) {
heldPoint.title = "Set Point"
heldPoint.subtitle = String(format: "%.4f", coordinates.latitude) + "," + String(format: "%.4f", coordinates.longitude)
mapView.addAnnotation(heldPoint)
}
// Cancel the long press gesture!
sender.state = .cancelled
}
通过这种微缩更改,LongPress消失了,点击由地图和注释处理。