I have several Circles in swiftui, that react on a touchgesture. I want them to increase the opac value and afterwards decrease it again:
HStack {
Spacer(minLength: 20.0)
Circle()
//#e74c3c
.foregroundColor(Color(red: 231.0/255.0, green: 76.0/255.0, blue: 60.0/255.0, opacity: buttonOpac[buttonColor.red.rawValue]))
.gesture(TapGesture()
.onEnded({if self.buttonActive {
self.buttonActive = false
self.blink(buttonColor.red)
} else {
print("button inactive")
}
})) ...
the method blink animates the change of the opac value:
func blink(_ buttonCol: buttonColor) {
self.currentNumber += 1
withAnimation(.easeOut(duration: blinkDuration)){
self.buttonOpac[buttonCol.rawValue] = 1.0
}
withAnimation(Animation.easeIn(duration: blinkDuration).delay(blinkDuration)){
self.buttonOpac[buttonCol.rawValue] = 0.5
}
withAnimation(Animation.linear.delay(2 * blinkDuration)){
self.buttonActive = true
}
}
For the time that this animation is active I want the circle to be disabled and not reacting on touches. I'll try to reach that by the @Status var buttonActive
This works only to the point, that setting this value to false on entry of the .onEnded block. Now I want to reset it in the blink method after the other animations have ended. But the delay modifier does not work for the third "animation". In fact the value is set immediately back to true so that the circle continues to react on touches.
Is the only way to reach the goal without the usage of timers?