π
First of all, you are trying to use the static "animate" method in an instance of myPositionPicker . And this is wrong. Just replace
myPositionPicker.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { yawpPositionPicker.transform = CGAffineTransform(translationX: 0, y: 0) }, completion: nil)
FROM
UIView.animate(withDuration: 1.5, delay: 0.05 * Double(index), usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: {
Further, if you want to create some simple animations (for example, changing the position of the UIImageView or changing its size), you can simply use the restrictions that have already been created and not use affine transformations.
For example, if your image is vertical with your map view. First, create a special @IBOutlet for this restriction in your UIViewController:
@IBOutlet var pickerCenterYConsraint: NSLayoutConstraint!
Secondly, plug this outlet into the restriction in the storyboard.
Thirdly, since I realized that your view controller is a delegate of your map view. So let me implement the map view delegate protocol as follows:
func mapView(_ mapView: MKMapView, regionWillChangeAnimated animated: Bool) { UIView.animate(withDuration: 1.5, delay: 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { self.pickerCenterYConsraint.constant = 25.0 self.view.layoutIfNeeded() }, completion: nil) } func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) { UIView.animate(withDuration: 1.5, delay: 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { self.pickerCenterYConsraint.constant = 0.0 self.view.layoutIfNeeded() }, completion: nil) }
And it's all! π€ Now your image will be animated while dragging the map. If you do not like this solution, you can create your own animation based on restrictions. Basically, you can do many things with restrictions. For example, with the exception of turns.