When I click on a UIButton, the @IBAction func pressPlay()
starts which, using a timer, moves the thumb of the slider (UISlider) every second.
The initial value of the slider is 0.
class MapViewController: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate,SCSEarthquakesHandler,SCSPublicSeismometersHandler
{
@IBOutlet weak var mapView: MKMapView!
@IBOutlet var sliderTime: UISlider!
@IBAction func pressPlay(_ sender: Any)
{
timer = Timer.scheduledTimer(withTimeInterval: 1,repeats: true)
{ [self]t in //ogni secondo questo timer cambia il valore dell'alpha del pin che sta vibrando
if cnt < 0
{
cnt = Int(self.sliderTime.value)
self.sliderTime.value += 1
let newDate2 = calendar2.date(byAdding: .day, value: Int(self.sliderTime.value), to:today)! //sottraggo alla data attuale il vlaore dello slider per tornare indietro nel tempo
format.dateStyle = .medium // "MM/GG/AAAA"
self.labelTime.text = "\(format.string(from: newDate2))"
}
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
{
print(Int(sliderTime.value))
...
}
}
I tried to recall the value of the slider inside the func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
but despite the slider has no value 0, when I go to print it in here it always returns value 0. Why?
I tried something ... I defined a global variable and initialized it to 0. I called it inside the mapView (...) function and increased it by 1. I noticed that it increments it every second (minus of a second). So I don't understand why sliderTime.value doesn't return the current value to me, but instead always 0.
How can I have the value of the slider printed during this animation?