Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func startTimer() {
- if imagePaths.count <= 1 { return }
- stopTimer()
- let dispatchTimer = DispatchSource.makeTimerSource()
- dispatchTimer.schedule(wallDeadline: .now()+duration, repeating: duration)
- dispatchTimer.setEventHandler { [weak self] in
- DispatchQueue.main.async {
- self?.scroll()
- }
- }
- dispatchTimer.resume()
- timer = dispatchTimer
- }
- func stopTimer() {
- timer?.cancel()
- timer = nil
- }
- fileprivate func scroll() {
- //帶動畫改變 scrollView 的偏移量實現自動滾動
- self.scrollView?.setContentOffset(CGPoint(x: self.scrollView!.bounds.size.width * 2, y: 0), animated: true)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement