Skip to content

Commit f1da073

Browse files
committed
#4 Added example of custom transition
1 parent 701b829 commit f1da073

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

ScrollStackController.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
6402E1F22347A8540087963C /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6402E1F12347A8540087963C /* Extension.swift */; };
1212
647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647C77B22348EA1600CAEB9F /* PricingVC.swift */; };
1313
6489C0612349C571003E5344 /* NotesVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6489C0602349C571003E5344 /* NotesVC.swift */; };
14+
649B1E9223B1251400BD6BFD /* ScrollStackRowAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B1E9123B1251400BD6BFD /* ScrollStackRowAnimator.swift */; };
15+
649B1E9323B1251900BD6BFD /* ScrollStackRowAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 649B1E9123B1251400BD6BFD /* ScrollStackRowAnimator.swift */; };
1416
64A8E8B32348CCCE00E893FB /* WelcomeVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */; };
1517
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C0224F234735A800A6D844 /* ScrollStackViewController.swift */; };
1618
64C02257234735A800A6D844 /* ScrollStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64C02250234735A800A6D844 /* ScrollStack.swift */; };
@@ -50,6 +52,7 @@
5052
6402E1F12347A8540087963C /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
5153
647C77B22348EA1600CAEB9F /* PricingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PricingVC.swift; sourceTree = "<group>"; };
5254
6489C0602349C571003E5344 /* NotesVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesVC.swift; sourceTree = "<group>"; };
55+
649B1E9123B1251400BD6BFD /* ScrollStackRowAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollStackRowAnimator.swift; sourceTree = "<group>"; };
5356
64A8E8B02348CCCE00E893FB /* WelcomeVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeVC.swift; sourceTree = "<group>"; };
5457
64C0224F234735A800A6D844 /* ScrollStackViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStackViewController.swift; sourceTree = "<group>"; };
5558
64C02250234735A800A6D844 /* ScrollStack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollStack.swift; sourceTree = "<group>"; };
@@ -131,6 +134,7 @@
131134
children = (
132135
64C0228523475A0E00A6D844 /* ScrollStack+Protocols.swift */,
133136
64C02253234735A800A6D844 /* UIView+AutoLayout_Extensions.swift */,
137+
649B1E9123B1251400BD6BFD /* ScrollStackRowAnimator.swift */,
134138
);
135139
path = Support;
136140
sourceTree = "<group>";
@@ -346,6 +350,7 @@
346350
64C02259234735A800A6D844 /* ScrollStackRow.swift in Sources */,
347351
64C02255234735A800A6D844 /* ScrollStackViewController.swift in Sources */,
348352
64C02257234735A800A6D844 /* ScrollStack.swift in Sources */,
353+
649B1E9223B1251400BD6BFD /* ScrollStackRowAnimator.swift in Sources */,
349354
64C0225D234735A800A6D844 /* UIView+AutoLayout_Extensions.swift in Sources */,
350355
64C0225B234735A800A6D844 /* ScrollStackSeparator.swift in Sources */,
351356
);
@@ -371,6 +376,7 @@
371376
64C0226C2347360800A6D844 /* ViewController.swift in Sources */,
372377
64C022812347582D00A6D844 /* ScrollStackSeparator.swift in Sources */,
373378
64C0227E2347582D00A6D844 /* ScrollStack.swift in Sources */,
379+
649B1E9323B1251900BD6BFD /* ScrollStackRowAnimator.swift in Sources */,
374380
64C022682347360800A6D844 /* AppDelegate.swift in Sources */,
375381
647C77B32348EA1600CAEB9F /* PricingVC.swift in Sources */,
376382
6402E1F22347A8540087963C /* Extension.swift in Sources */,

ScrollStackControllerDemo/Child View Controllers/WelcomeVC.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,34 @@ public class WelcomeVC: UIViewController, ScrollStackContainableController {
2424
}
2525

2626
public func reloadContentFromStackView(stackView: ScrollStack, row: ScrollStackRow, animated: Bool) {
27+
28+
}
29+
30+
}
31+
32+
extension WelcomeVC: ScrollStackRowAnimatable {
33+
34+
public var animationInfo: ScrollStackAnimationInfo {
35+
return ScrollStackAnimationInfo(duration: 1, delay: 0, springDamping: 0.8)
36+
}
2737

38+
public func animateTransition(toHide: Bool) {
39+
switch toHide {
40+
case true:
41+
self.view.transform = CGAffineTransform(translationX: -100, y: 0)
42+
self.view.alpha = 0
43+
44+
case false:
45+
self.view.transform = .identity
46+
self.view.alpha = 1
47+
}
48+
}
49+
50+
public func willBeginAnimationTransition(toHide: Bool) {
51+
if toHide == false {
52+
self.view.transform = CGAffineTransform(translationX: -100, y: 0)
53+
self.view.alpha = 0
54+
}
2855
}
2956

3057
}

Sources/ScrollStackController/Support/ScrollStackRowAnimator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public protocol ScrollStackRowAnimatable {
5555

5656
// MARK: - ScrollStackRowAnimatable Extension
5757

58-
public extension ScrollStackRowAnimatable where Self: UIView {
58+
public extension ScrollStackRowAnimatable where Self: UIViewController {
5959

6060
var animationInfo: ScrollStackAnimationInfo {
6161
return ScrollStackAnimationInfo()
@@ -116,7 +116,7 @@ internal class ScrollStackRowAnimator {
116116

117117
/// Target row if animatable.
118118
private var animatableRow: ScrollStackRowAnimatable? {
119-
return targetRow.contentView as? ScrollStackRowAnimatable
119+
return targetRow.controller as? ScrollStackRowAnimatable
120120
}
121121

122122
// MARK: - Initialization

0 commit comments

Comments
 (0)