I've been trying to add multiple haptic events based on when each view I have animates in, however when testing it only plays the first haptic and stops there. I've tried searching online if it's even possible to play multiple haptics in a short space of time (would the Taptic Engine be ready to fire off multiple times that quickly?) but couldn't find anything.
Anyone know if this is even possible and if so why mine might not be working?
I've tried 2 different methods of adding multiple haptics in:
Here's my code for the first method, where I'm initialising a new instance first and then playing the same haptic within each animation block with a 0.25 delay between animations:
Here's the 2nd method I've tried, where I initialise and play a new haptic within each animation block:
So far both methods only play the first haptic and stop right there. Any ideas if this works? Thanks.
Anyone know if this is even possible and if so why mine might not be working?
I've tried 2 different methods of adding multiple haptics in:
Here's my code for the first method, where I'm initialising a new instance first and then playing the same haptic within each animation block with a 0.25 delay between animations:
Code Block func animateSunriseAndSunsetViews() { let generator = UIImpactFeedbackGenerator(style: .medium) generator.prepare() sunriseView.alpha = 0 morningGoldenHourView.alpha = 0 morningWeatherLabel.alpha = 0 morningGoldenHourWeatherView.alpha = 0 eveningGoldenHourView.alpha = 0 sunsetView.alpha = 0 eveningWeatherLabel.alpha = 0 eveningGoldenHourWeatherView.alpha = 0 nextGoldenHourLabel.alpha = 0 UIView.animate(withDuration: 1, delay: 0, options: .curveEaseInOut) { self.sunriseView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 0.25, options: .curveEaseInOut) { self.morningGoldenHourView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 0.5, options: .curveEaseInOut) { self.eveningGoldenHourView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 0.75, options: .curveEaseInOut) { self.sunsetView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 1, options: .curveEaseInOut) { self.morningWeatherLabel.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 1.25, options: .curveEaseInOut) { self.morningGoldenHourWeatherView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 1.5, options: .curveEaseInOut) { self.eveningWeatherLabel.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 1.75, options: .curveEaseInOut) { self.eveningGoldenHourWeatherView.alpha = 100 generator.impactOccurred() } UIView.animate(withDuration: 1, delay: 2, options: .curveEaseInOut) { self.nextGoldenHourLabel.alpha = 100 generator.impactOccurred() } }
Here's the 2nd method I've tried, where I initialise and play a new haptic within each animation block:
Code Block func animateSunsetViews() { eveningGoldenHourView.alpha = 0 sunsetView.alpha = 0 eveningWeatherLabel.alpha = 0 eveningGoldenHourWeatherView.alpha = 0 nextGoldenHourLabel.alpha = 0 UIView.animate(withDuration: 1, delay: 0, options: .curveEaseInOut) { self.eveningGoldenHourView.alpha = 100 let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) } UIView.animate(withDuration: 1, delay: 0.25, options: .curveEaseInOut) { self.sunsetView.alpha = 100 let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) } UIView.animate(withDuration: 1, delay: 0.5, options: .curveEaseInOut) { self.eveningWeatherLabel.alpha = 100 let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) } UIView.animate(withDuration: 1, delay: 0.75, options: .curveEaseInOut) { self.eveningGoldenHourWeatherView.alpha = 100 let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) } UIView.animate(withDuration: 1, delay: 1, options: .curveEaseInOut) { self.nextGoldenHourLabel.alpha = 100 let generator = UINotificationFeedbackGenerator() generator.notificationOccurred(.success) } }
So far both methods only play the first haptic and stop right there. Any ideas if this works? Thanks.