지도에서 적절한 주석보기를 열었습니다. 주석 프레임을주고 핀, 그 시간 팝업보기 프레임을 선택하십시오.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
// Better to make this class property
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = MKAnnotationView()
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView.frame = CGRect(x: annotationView.frame.origin.x, y: annotationView.frame.origin.y, width: 80, height: 200)
annotationView.annotation = annotation
annotationView.tag = index
index += 1
let imageViewPin = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 40))
imageViewPin.center = CGPoint(x: annotationView.center.x, y: annotationView.center.y - 11)
imageViewPin.image = UIImage(named: "green_pin")
annotationView.addSubview(imageViewPin)
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
debugPrint(view.tag)
let overlays = self.mapVW.overlays
self.mapVW.removeOverlays(overlays)
if viewPopUp != nil {
viewPopUp.removeFromSuperview()
for item in viewPopUp.subviews
{
item.removeFromSuperview()
}
}
if arrPin.count >= view.tag {
let dictList = self.arrPin.object(at: view.tag) as? NSDictionary
viewPopUp = UIView(frame: CGRect(x: -98, y: 10, width: 250, height: 60))
view.addSubview(viewPopUp)
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: viewPopUp.frame.size.width, height: viewPopUp.frame.size.height))
imageView.image = UIImage(named: "ic_mappopupbackground")
imageView.contentMode = .scaleAspectFit
let imgCar = UIImageView(frame: CGRect(x: imageView.frame.origin.x + 25, y: 9, width: 30, height: 20))
imgCar.image = UIImage(named: "ic_car")
imgCar.contentMode = .scaleAspectFit
let lblMin = UILabel(frame: CGRect(x: imageView.frame.origin.x + 18, y: 33, width: 45, height: 15))
lblMin.textColor = UIColor.white
lblMin.textAlignment = .center
lblMin.font = UIFont(name: "HelveticaNeue-Light", size: 11)
let totalDist = distance(lat: dictList?.value(forKey: "lat") as! String, long: dictList?.value(forKey: "lon") as! String)
lblMin.text = "\(totalDist) mi"
let lblName = UILabel(frame: CGRect(x: imageView.frame.origin.x + 70, y: 5, width: 150, height: 25))
lblName.textColor = UIColor.black
lblName.textAlignment = .natural
lblName.adjustsFontSizeToFitWidth = true
lblName.numberOfLines = 0
lblName.lineBreakMode = .byCharWrapping
lblName.font = UIFont(name: "HelveticaNeue-CondensedBold", size: 18)
lblName.text = dictList?.value(forKey: "name") as? String
let lblCategory = UILabel(frame: CGRect(x: imageView.frame.origin.x + 72, y: lblName.frame.origin.y + 25, width: imageView.frame.size.width - 30, height: 18))
lblCategory.textColor = UIColor(red: 151/255, green: 151/255, blue: 151/255, alpha: 1.0)
lblCategory.textAlignment = .natural
lblCategory.font = UIFont(name: "HelveticaNeue-Light", size: 14)
lblCategory.text = txtSearch.text
viewPopUp.addSubview(imageView)
viewPopUp.addSubview(imgCar)
viewPopUp.addSubview(lblMin)
viewPopUp.addSubview(lblName)
viewPopUp.addSubview(lblCategory)
// viewPopUp.addSubview(btnRoute)
viewPopUp.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(btnRouteView(sender:)))
self.selectIndex = view.tag
viewPopUp.addGestureRecognizer(tap)
}
}
일부 코드는 일부 이미지 게시와 함께 우리는 어떤 식 으로든 당신을 도울 수 없습니다 –