Naturally, Indicator of ScrollView is visible when the content view of ScrollView is longer than ScrollView height and user drag on Screen. As we all know It is a default functionality, we can't make it always visible directly.
Using flashScrollIndicators()
method we can make it visible.
Example
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
scrollView.flashScrollIndicators()
}
But indicator only appears for some time after viewDidAppear method call and disappear again. Indicator only to reappear when the user touches the screen.
To show indicator continuously without touching screen you can add flashScrollIndicators() method in Timer. Timers work in continuously with run loops. Run loops maintain strong references to their timers, so you don’t have to maintain once you add a timer in run loop.
Example
var timerForShowScrollIndicator: Timer?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
startTimerForShowScrollIndicator()
}
@objc func showScrollIndicatorsInContacts() {
UIView.animate(withDuration: 0.001) {
self.scrollView.flashScrollIndicators()
}
}
func startTimerForShowScrollIndicator() {
self.timerForShowScrollIndicator = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.showScrollIndicatorsInContacts), userInfo: nil, repeats: true)
}
Using this method indicator is always visible without touches on Screen until the user does not stop Timer.