Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. func startTimer() {
  2. if imagePaths.count <= 1 { return }
  3.  
  4. stopTimer()
  5. let dispatchTimer = DispatchSource.makeTimerSource()
  6. dispatchTimer.schedule(wallDeadline: .now()+duration, repeating: duration)
  7. dispatchTimer.setEventHandler { [weak self] in
  8. DispatchQueue.main.async {
  9. self?.scroll()
  10. }
  11. }
  12. dispatchTimer.resume()
  13. timer = dispatchTimer
  14. }
  15.  
  16. func stopTimer() {
  17. timer?.cancel()
  18. timer = nil
  19. }
  20.  
  21. fileprivate func scroll() {
  22. //帶動畫改變 scrollView 的偏移量實現自動滾動
  23. self.scrollView?.setContentOffset(CGPoint(x: self.scrollView!.bounds.size.width * 2, y: 0), animated: true)
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement