@@ -12,13 +12,15 @@ import Pages
1212public class PresentationController : PagesController {
1313
1414 public weak var presentationDelegate : PresentationControllerDelegate ?
15+ public var maxAnimationDelay : Double = 3
1516
1617 private var backgroundContents = [ Content] ( )
1718 private var slides = [ SlideController] ( )
1819 private var animationsForPages = [ Int : [ Animatable] ] ( )
1920
2021 private var animationIndex = 0
2122 private weak var scrollView : UIScrollView ?
23+ var animationTimer : NSTimer ?
2224
2325 public convenience init ( pages: [ UIViewController ] ) {
2426 self . init (
@@ -55,6 +57,8 @@ public class PresentationController: PagesController {
5557 // MARK: - Public methods
5658
5759 public override func goTo( index: Int ) {
60+ startAnimationTimer ( )
61+
5862 super. goTo ( index)
5963
6064 if index >= 0 && index < pagesCount {
@@ -82,6 +86,33 @@ public class PresentationController: PagesController {
8286 } )
8387 }
8488 }
89+
90+ // MARK: - Animation Timer
91+
92+ func startAnimationTimer( ) {
93+ stopAnimationTimer ( )
94+ scrollView? . userInteractionEnabled = false
95+ if animationTimer == nil {
96+ dispatch_async ( dispatch_get_main_queue ( ) ) {
97+ self . animationTimer = NSTimer . scheduledTimerWithTimeInterval ( self . maxAnimationDelay,
98+ target: self ,
99+ selector: " updateAnimationTimer: " ,
100+ userInfo: nil ,
101+ repeats: false )
102+ NSRunLoop . currentRunLoop ( ) . addTimer ( self . animationTimer!, forMode: NSRunLoopCommonModes)
103+ }
104+ }
105+ }
106+
107+ func stopAnimationTimer( ) {
108+ animationTimer? . invalidate ( )
109+ animationTimer = nil
110+ }
111+
112+ func updateAnimationTimer( timer: NSTimer ) {
113+ stopAnimationTimer ( )
114+ scrollView? . userInteractionEnabled = true
115+ }
85116}
86117
87118// MARK: - Content
0 commit comments