0

I am trying to print something to the consol when my progress view reaches its max value. I have a long press gesture recogniser on the progress view where the user holds the view down for 5 seconds and that increases the progress views value. I would like to print something to the consol when the progress view value reaches the max value.

I have tried something along the lines of

if progressView.value == 5 {
print("message")
}

This prints the message as soon as the user presses the view, it doesnt wait until the value = 5.

I am using MBCircularProgressBarView

Thanks

 @IBAction func buttonPressed(_ sender: UILongPressGestureRecognizer) {

    if sender.state == .began {
        UIView.animate(withDuration: 5) {

            self.progressView.value = 5
        }
    }

    if sender.state == .ended {

        UIView.animate(withDuration: 2) {
            self.progressView.value = 0
        }
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rob
  • 73
  • 7

1 Answers1

-1

I think I see your error in the first if statement you are setting the progressView.value to 5 as soon as the touch begins, that's why you see the log in the console right away, I would suggest something like the following

if sender.state == .began {
    UIView.animate(withDuration: 5) {

        self.progressView.value += 1

        if progressView.value == 5 {
           print("message")
        }

    }
}
Samuel Chavez
  • 768
  • 9
  • 12