Skip to content

Commit 96dddea

Browse files
committed
Merge pull request #72 from hyperoslo/fix/scrolling-and-animation
Fix scrolling and animation
2 parents 061e37f + ec8e869 commit 96dddea

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

Presentation.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ Pod::Spec.new do |s|
1313

1414
s.source_files = 'Source/**/*'
1515
s.dependency 'Pages', '~> 0.6.2'
16-
s.dependency 'Cartography', '~> 0.6.0'
16+
s.dependency 'Cartography'
1717
end

Source/Animations/TransitionAnimation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public class TransitionAnimation: NSObject, Animatable {
3535
delay: 0,
3636
usingSpringWithDamping: dumping,
3737
initialSpringVelocity: 0.5,
38-
options: [.BeginFromCurrentState, .AllowUserInteraction],
38+
options: [.BeginFromCurrentState, .AllowUserInteraction, .LayoutSubviews],
3939
animations: { [unowned self] in
4040
self.content.position = position
41+
self.content.view.superview!.layoutIfNeeded()
4142
}, completion: nil)
4243

4344
played = true

Source/Content.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class Content: NSObject {
4444
view.top == y
4545
}
4646
}
47-
view.superview!.layoutIfNeeded()
47+
view.layoutIfNeeded()
4848
}
4949
}
5050
}

Source/PresentationController.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import Pages
1212
public 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

Comments
 (0)