I want to show a storyboard View whenever a user taps on an annotation and it's subtitle is visible. My code works somewhat but isn't doing exactly what I want. Here's my code
import MapKit
class ViewController: UIViewController,MKMapViewDelegate {
@IBOutlet weak var homeMapView: MKMapView!
let annotation = MKPointAnnotation()
@IBOutlet weak var viewToShow:UIView!
override func viewDidLoad() {
super.viewDidLoad()
setupMapPin()
viewToShow.transform = CGAffineTransform(translationX: 0, y: 450)
}
func setupMapPin() {
homeMapView.delegate = self
annotation.coordinate = CLLocationCoordinate2D(latitude: 9.0833, longitude: 7.5361)
homeMapView.addAnnotation(annotation)
annotation.title = "Title"
annotation.subtitle = "Randome subtitle"
let defaultRegion = MKCoordinateRegion(center: annotation.coordinate, latitudinalMeters: 2000, longitudinalMeters: 2000)
homeMapView.setRegion(defaultRegion, animated: true)
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if boatview.transform == .identity {
UIView.animate(withDuration: 1) {
self.boatview.transform = CGAffineTransform(translationX: 0, y: 450)
}
} else {
UIView.animate(withDuration:1) {
self.boatview.transform = .identity
}
}
}
}
` I want the view to animate in when the user clicks the annotation and the subtitle is visible i.e when the annotation is active. The view animates in when the annotation is clicked and active but doesn't animate out when it's inactive. What am I not doing right here?