Пин-код для MKAnnotation
. При касании или увеличении карты пользовательский штифт растягивается, и отверстие для маркера автомобиля на домашней карте большого размера. Вот результат вывода, который я получаю в mapview:
Вот код, который я пробовал до сих пор:
var pin = MKAnnotationView()
var userPinView: MKAnnotationView!
if annotation is MKUserLocation {
pin = mapView.view(for: annotation) ?? MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
let pinImage = UIImage(named: "carIcon3")
let size = CGSize(width: 38, height: 44)
UIGraphicsBeginImageContext(size)
pinImage!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
pin.image = resizedImag
userPinView = pin
userPinView.contentMode = .scaleAspectFill
userPinView.clipsToBounds = true
return pin
}
if !(annotation is MKPointAnnotation) {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
// annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
Как получить такой результат:
Попытка пользователя маркер текущего местоположения. Но это сбой
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
UIView.animate(withDuration: 0.005) {
let angle = newHeading.trueHeading.toRadians() // convert from degrees to radians
self.userPinView.transform = CGAffineTransform(rotationAngle: CGFloat(angle)) // rotate the picture
}
}
здесь код, который я выполнил didselect и снимите выделение для аннотации местоположения.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if annotView == true {
let heights = 70
let widths = 50
UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveLinear, animations: {
view.frame.size = CGSize(width: widths, height: heights)
})
}
}
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
let heights = 70
let widths = 50
UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveLinear, animations: {
view.frame.size = CGSize(width: view.frame.width - CGFloat(widths), height: view.frame.height - CGFloat(heights))
})
}