我向annotationview添加了一个子视图,并加载了customview pin。我当前的问题是,当我单击注释pin(自定义视图pin)时,我无法查看我的详图索引视图。
我创建了一个标签并将其添加到detailCalloutAccessoryView,因为我的标注文本非常大。有没有办法显示此标注
这是我的密码
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
var subTitlelbl = UILabel()
// subTitlelbl.text = "sri ganganagar this is my home twon.sri ganganagar this is my home twon.sri ganganagar this is my home twon. "
var width = NSLayoutConstraint(item: subTitlelbl, attribute: .width, relatedBy: .lessThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 150)
var height = NSLayoutConstraint(item: subTitlelbl, attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 0)
subTitlelbl.numberOfLines = 0
subTitlelbl.addConstraint(width)
subTitlelbl.addConstraint(height)
if annotation is MKUserLocation
{
return nil
}
var annotationView = self.appleMap.dequeueReusableAnnotationView(withIdentifier: "Pin") //as? SVPulsingAnnotationView
var pulseView = self.appleMap.dequeueReusableAnnotationView(withIdentifier: "Pin1") as? SVPulsingAnnotationView
if annotationView == nil || pulseView == nil
{
annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "Pin") //as? SVPulsingAnnotationView
pulseView = self.appleMap.dequeueReusableAnnotationView(withIdentifier: "Pin1") as? SVPulsingAnnotationView
annotationView?.canShowCallout = true
pulseView?.canShowCallout = true
}
else
{
annotationView?.annotation = annotation
pulseView?.annotation = annotation
annotationView?.canShowCallout = true
pulseView?.canShowCallout = true
}
print("annotation.coordinate : ", annotation.coordinate.latitude.description)
let myCustomView:CustomView = UINib(nibName: "CustomView", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! CustomView
if ( if (annotation is IgnitionAnnotationView)
{
myCustomView.customMarkerIconImage.image = #imageLiteral(resourceName: "icon_idle")
myCustomView.longArrowImage.image = nil
myCustomView.customTruckImage.image = nil
// var button = UIButton(type: UIButtonType.system) as! UIButton
// button.frame = myCustomView.frame
// button.backgroundColor = UIColor.clear
// button.addTarget(self, action: "buttonAction:", for: UIControlEvents.touchUpInside)
// // button.setTitle("selected", for: .normal)
// // button.setTitleColor(UIColor.black, for: .normal)
// button.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left
// myCustomView.addSubview(button)
// button.tag = 2
subTitlelbl.text = annotation.subtitle!
print("(annotation.subtitle) = ",annotation.subtitle!)
annotationView?.detailCalloutAccessoryView = subTitlelbl
annotationView?.canShowCallout = true
// self.appleMap.selectAnnotation(annotation, animated: true)
// annotationView?.isSelected = true
// annotationView?.
}
else
{
myCustomView.customMarkerIconImage.image = #imageLiteral(resourceName: "green_custom_marker_icon")
myCustomView.longArrowImage.image = #imageLiteral(resourceName: "east")
myCustomView.customTruckImage.image = #imageLiteral(resourceName: "truck_east")
let pulseHalo = SVPulsingAnnotationView()
annotationView?.sendSubview(toBack: pulseHalo)
if slideCurrentValue < 0.6
{
pulseHalo.delayBetweenPulseCycles = 3
pulseHalo.outerColor = .green
pulseHalo.annotationColor = .green
pulseHalo.pulseScaleFactor = 20
pulseHalo.pulseColor = .black
}
else
{
pulseHalo.delayBetweenPulseCycles = 0
pulseHalo.outerColor = .green
pulseHalo.annotationColor = .green
pulseHalo.pulseScaleFactor = 1
pulseHalo.pulseColor = .black
}
pulseHalo.frame = CGRect(x: 15, y: 20, width: 5, height: 5)
annotationView?.addSubview(pulseHalo)
}
annotationView?.centerOffset = CGPoint(x: 0,y: (annotationView?.frame.size.height)!*(-0.5));
annotationView?.addSubview(myCustomView)
pulseView?.addSubview(myCustomView)
pulseView?.centerOffset = CGPoint(x: -15,y: -38)
annotationView?.bringSubview(toFront: myCustomView)
annotationView?.centerOffset = CGPoint(x: -15,y: -38)
return annotationView
}
}
我的点火注释视图是
class IgnitionAnnotationView: NSObject, MKAnnotation
{
var title: String?
var subtitle: String?
var latitude: Double
var longitude:Double
var coordinate: CLLocationCoordinate2D
{
return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
}
init(latitude: Double, longitude: Double)
{
self.latitude = latitude
self.longitude = longitude
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}