[英]How can I make a UIButton within PinView open a pop up view?
您好,所以我正在使用此应用程序,因此可以按PinView中的按钮,它将加载一个弹出视图。 我对如何使它正常工作感到非常困惑,因为我认为我需要将它作为IBAction使用,但我认为我不能做到这一点,因为它被隐藏在main.storyboard中。
extension ViewController : MKMapViewDelegate {
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView?.pinTintColor = UIColor(red: 52/255.0, green: 73/255.0, blue: 94/255.0, alpha: 1.0)
pinView?.canShowCallout = true
let removeButton = UIButton(type: .Custom)
removeButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
removeButton.setImage(UIImage(named: "RadiusSettings")!, forState: .Normal)
pinView?.leftCalloutAccessoryView = removeButton
return pinView
}
}
任何帮助,将不胜感激,谢谢
在地图视图的delegate
,实现calloutAccessoryControlTapped
。
我认为您不能轻易在注解视图中放置一个按钮,但是正如Matt所言,您可以在用户点击注解视图时显示的标注视图中添加一个按钮。
用户需要点击显示标注视图的注释视图(通常是图钉),如果已添加,则包括一个按钮。 然后,用户点击标注上的按钮,然后调用calloutAccessoryControlTapped
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.