Reputation: 51
in my app there are 3 screens in the onboarding/splash screen flows which are set to auto rotate every 5 seconds
private var pageChangeTimer: Timer?
let pageChangeInterval: TimeInterval = 5.0
var pageChangeTimer = Timer.scheduledTimer(
withTimeInterval: pageChangeInterval,
repeats: true) { [weak self] timer in
self?.rotateScreen()
}
how to stop auto rotate after one rotation of all three screens in onboarding flow for splash screens
Upvotes: 0
Views: 43
Reputation: 100503
You can use timer's invalidate()
instance method to stop it
var counter = 0
pageChangeTimer = Timer.scheduledTimer( withTimeInterval: pageChangeInterval, repeats: true) { [weak self] timer in
self?.rotateScreen()
self.counter += 1
if self.counter == 3 {
timer.invalidate()
}
}
Upvotes: 1