Skip to content

Commit 7797a48

Browse files
committed
Merge branch 'release/1.1.0'
2 parents 5397ffd + c6fbc41 commit 7797a48

File tree

12 files changed

+171
-81
lines changed

12 files changed

+171
-81
lines changed

Presentr.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "Presentr"
3-
s.version = "1.0.5"
3+
s.version = "1.1.0"
44
s.summary = "A simple Swift wrapper for typical custom view controller presentations."
55
s.description = <<-DESC
66
A micro framework created in Swift. Simplifies creating custom view controller presentations. Specially the typical ones we use which are a popup, an alert, or a any non-full-screen modal. Abstracts having to deal with custom presentation controllers and transitioning delegates
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
1010
s.author = { "Daniel Lozano" => "dan@danielozano.com" }
1111
s.social_media_url = "http://twitter.com/danlozanov"
1212
s.platform = :ios, "9.0"
13-
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.0.5" }
13+
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.1.0" }
1414
s.source_files = "Presentr/**/*.{swift}"
1515
s.resources = "Presentr/**/*.{xib,ttf}"
1616
end

Presentr.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
061412091E1316990049FF99 /* SpringFromBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */; };
1011
06686C741CE8248D00F88216 /* PresentrAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C731CE8248D00F88216 /* PresentrAnimation.swift */; };
1112
06686C761CE8250200F88216 /* CoverVerticalFromTopAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */; };
1213
06686C9D1CE947E200F88216 /* CoverHorizontalAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */; };
@@ -38,6 +39,7 @@
3839
/* End PBXContainerItemProxy section */
3940

4041
/* Begin PBXFileReference section */
42+
061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpringFromBottomAnimation.swift; sourceTree = "<group>"; };
4143
06686C731CE8248D00F88216 /* PresentrAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentrAnimation.swift; sourceTree = "<group>"; };
4244
06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoverVerticalFromTopAnimation.swift; sourceTree = "<group>"; };
4345
06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoverHorizontalAnimation.swift; sourceTree = "<group>"; };
@@ -86,6 +88,7 @@
8688
06686C731CE8248D00F88216 /* PresentrAnimation.swift */,
8789
06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */,
8890
06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */,
91+
061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */,
8992
);
9093
name = Animation;
9194
sourceTree = "<group>";
@@ -294,6 +297,7 @@
294297
buildActionMask = 2147483647;
295298
files = (
296299
06686C761CE8250200F88216 /* CoverVerticalFromTopAnimation.swift in Sources */,
300+
061412091E1316990049FF99 /* SpringFromBottomAnimation.swift in Sources */,
297301
06B5855B1D2D6F8B0045C8DA /* TransitionType.swift in Sources */,
298302
06B5855F1D2D6FE20045C8DA /* ModalCenterPosition.swift in Sources */,
299303
06686C9D1CE947E200F88216 /* CoverHorizontalAnimation.swift in Sources */,

Presentr/CoverHorizontalAnimation.swift

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,22 @@
88

99
import Foundation
1010

11-
/// Custom 'CoverHorizontalAnimation' animation. Conforms to 'PresentrAnimation' protocol
12-
class CoverHorizontalAnimation: NSObject, PresentrAnimation {
11+
class CoverHorizontalAnimation: PresentrAnimation {
1312

14-
var animationDuration: TimeInterval
15-
var fromRight: Bool
13+
private var fromRight: Bool
1614

17-
init(animationDuration: TimeInterval = 0.5, fromRight: Bool = true) {
18-
self.animationDuration = animationDuration
15+
init(fromRight: Bool = true) {
1916
self.fromRight = fromRight
2017
}
2118

22-
}
23-
24-
// MARK: UIViewControllerAnimatedTransitioning
25-
26-
extension CoverHorizontalAnimation: UIViewControllerAnimatedTransitioning {
27-
28-
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
29-
return animationDuration
30-
}
31-
32-
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
33-
animate(transitionContext) { finalFrame, containerFrame in
34-
var initialFrame = finalFrame
35-
if self.fromRight {
36-
initialFrame.origin.x = containerFrame.size.width + initialFrame.size.width
37-
} else {
38-
initialFrame.origin.x = 0 - initialFrame.size.width
39-
}
40-
return initialFrame
19+
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
20+
var initialFrame = finalFrame
21+
if fromRight {
22+
initialFrame.origin.x = containerFrame.size.width + initialFrame.size.width
23+
} else {
24+
initialFrame.origin.x = 0 - initialFrame.size.width
4125
}
26+
return initialFrame
4227
}
4328

4429
}

Presentr/CoverVerticalFromTopAnimation.swift

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,12 @@
88

99
import Foundation
1010

11-
/// Custom 'CoverVerticalFromTopAnimation' animation. Conforms to 'PresentrAnimation' protocol
12-
class CoverVerticalFromTopAnimation: NSObject, PresentrAnimation {
11+
class CoverVerticalFromTopAnimation: PresentrAnimation {
1312

14-
var animationDuration: TimeInterval
15-
16-
init(animationDuration: TimeInterval = 0.5) {
17-
self.animationDuration = animationDuration
18-
}
19-
20-
}
21-
22-
// MARK: UIViewControllerAnimatedTransitioning
23-
24-
extension CoverVerticalFromTopAnimation: UIViewControllerAnimatedTransitioning {
25-
26-
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
27-
return animationDuration
28-
}
29-
30-
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
31-
animate(transitionContext) { finalFrame, _ in
32-
var initialFrame = finalFrame
33-
initialFrame.origin.y = 0 - initialFrame.size.height
34-
return initialFrame
35-
}
13+
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
14+
var initialFrame = finalFrame
15+
initialFrame.origin.y = 0 - initialFrame.size.height
16+
return initialFrame
3617
}
3718

3819
}

Presentr/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.4</string>
18+
<string>1.1.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Presentr/PresentrAnimation.swift

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,61 @@
88

99
import Foundation
1010

11-
/**
12-
* Protocol that represents a custom PresentrAnimation. Conforms to 'UIViewControllerAnimatedTransitioning'
13-
*/
14-
protocol PresentrAnimation: UIViewControllerAnimatedTransitioning {
11+
/// Class that handles animating the transition. Override this class if you want to create your own transition animation.
12+
open class PresentrAnimation: NSObject {
1513

16-
/// The duration for the animation. Must be set by the class that implements protocol.
17-
var animationDuration: TimeInterval { get set }
14+
/// Spring damping for the UIView animation. Default is 300. Override to customize.
15+
open var springDamping: CGFloat {
16+
return 300
17+
}
1818

19-
/**
20-
This method has a default implementation by the 'PresentrAnimation' extension. It handles animating the view controller.
19+
/// Initial spring velocity for the UIView animation. Default is 5. Override to customize.
20+
open var initialSpringVelocity: CGFloat {
21+
return 5
22+
}
2123

22-
- parameter transitionContext: Receives the transition context from the class implementing the protocol
23-
- parameter transform: Transform block used to obtain the initial frame for the animation, given the finalFrame and the container's frame.
24+
/// Animation duration. Default is 0.5, override to customize.
25+
open var animationDuration: TimeInterval {
26+
return 0.5
27+
}
2428

25-
*/
26-
func animate(_ transitionContext: UIViewControllerContextTransitioning, transform: FrameTransformer)
29+
/// Method used to create an initial frame for the animation. Override to customize, default is 0,0,0,0.
30+
///
31+
/// - Parameters:
32+
/// - containerFrame: The container frame.
33+
/// - finalFrame: The final frame for the view controller.
34+
/// - Returns: The initial frame for the animation.
35+
open func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
36+
var initialFrame = finalFrame
37+
initialFrame.origin.y = containerFrame.height + initialFrame.height
38+
return initialFrame
39+
}
40+
41+
42+
/// If you want to completely handle the transition animation on your own, override this method and return true. If you return true and handle the animation on your own, all the other animation properties of this class will be ignored.
43+
///
44+
/// - Parameter transitionContext: The transition context for the transition animation.
45+
/// - Returns: A boolean indicating if you want to use this custom animation instead of the included version.
46+
open func customAnimation(using transitionContext: UIViewControllerContextTransitioning) -> Bool {
47+
return false
48+
}
2749

2850
}
2951

30-
/// Transform block used to obtain the initial frame for the animation, given the finalFrame and the container's frame.
31-
typealias FrameTransformer = (_ finalFrame: CGRect, _ containerFrame: CGRect) -> CGRect
52+
// MARK: - UIViewControllerAnimatedTransitioning
3253

33-
extension PresentrAnimation {
54+
extension PresentrAnimation: UIViewControllerAnimatedTransitioning {
55+
56+
public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
57+
return animationDuration
58+
}
59+
60+
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
61+
let custom = customAnimation(using: transitionContext)
62+
guard custom == false else {
63+
return
64+
}
3465

35-
func animate(_ transitionContext: UIViewControllerContextTransitioning, transform: FrameTransformer) {
3666
let containerView = transitionContext.containerView
3767

3868
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)
@@ -46,7 +76,7 @@ extension PresentrAnimation {
4676
let animatingView = isPresenting ? toView : fromView
4777

4878
let finalFrameForVC = transitionContext.finalFrame(for: animatingVC!)
49-
let initialFrameForVC = transform(finalFrameForVC, containerView.frame)
79+
let initialFrameForVC = transform(containerFrame: containerView.frame, finalFrame: finalFrameForVC)
5080

5181
let initialFrame = isPresenting ? initialFrameForVC : finalFrameForVC
5282
let finalFrame = isPresenting ? finalFrameForVC : initialFrameForVC
@@ -59,19 +89,23 @@ extension PresentrAnimation {
5989

6090
animatingView?.frame = initialFrame
6191

62-
UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 300.0, initialSpringVelocity: 5.0, options: .allowUserInteraction, animations: {
63-
64-
animatingView?.frame = finalFrame
65-
66-
}, completion: { (value: Bool) in
92+
UIView.animate(withDuration: duration,
93+
delay: 0,
94+
usingSpringWithDamping: springDamping,
95+
initialSpringVelocity: initialSpringVelocity,
96+
options: .allowUserInteraction,
97+
animations: {
6798

68-
if !isPresenting {
69-
fromView?.removeFromSuperview()
70-
}
99+
animatingView?.frame = finalFrame
71100

72-
let wasCancelled = transitionContext.transitionWasCancelled
73-
transitionContext.completeTransition(!wasCancelled)
101+
}, completion: { (value: Bool) in
74102

103+
if !isPresenting {
104+
fromView?.removeFromSuperview()
105+
}
106+
let wasCancelled = transitionContext.transitionWasCancelled
107+
transitionContext.completeTransition(!wasCancelled)
108+
75109
})
76110
}
77111

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// SpringFromBottomAnimation.swift
3+
// PresentrExample
4+
//
5+
// Created by Francesco Perrotti-Garcia on 12/26/16.
6+
// Copyright © 2016 Presentr. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class SpringFromBottomAnimation: PresentrAnimation {
12+
13+
override var springDamping: CGFloat {
14+
return 0.5
15+
}
16+
17+
override var initialSpringVelocity: CGFloat {
18+
return 0
19+
}
20+
21+
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
22+
var initialFrame = finalFrame
23+
initialFrame.origin.y = containerFrame.size.height + initialFrame.size.height
24+
return initialFrame
25+
}
26+
27+
}

Presentr/TransitionType.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Foundation
1717
- CoverVerticalFromTop: Custom transition animation. Slides in vertically from top.
1818
- CoverHorizontalFromLeft: Custom transition animation. Slides in horizontally from left.
1919
- CoverHorizontalFromRight: Custom transition animation. Slides in horizontally from right.
20+
- Custom: Custom transition animation provided by the user.
2021
*/
2122
public enum TransitionType {
2223

@@ -28,6 +29,9 @@ public enum TransitionType {
2829
case coverVerticalFromTop
2930
case coverHorizontalFromRight
3031
case coverHorizontalFromLeft
32+
case coverVerticalWithSpring
33+
// User defined
34+
case custom(PresentrAnimation)
3135

3236
/**
3337
Maps the 'TransitionType' to the system provided transition.
@@ -61,6 +65,10 @@ public enum TransitionType {
6165
return CoverHorizontalAnimation(fromRight: true)
6266
case .coverHorizontalFromLeft:
6367
return CoverHorizontalAnimation(fromRight: false)
68+
case .coverVerticalWithSpring:
69+
return SpringFromBottomAnimation()
70+
case .custom(let animation):
71+
return animation
6472
default:
6573
return nil
6674
}

PresentrExample/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ platform :ios, '9.0'
22
use_frameworks!
33

44
target 'PresentrExample' do
5-
pod 'Presentr'
5+
pod 'Presentr', :path => '../'
66
end

PresentrExample/PresentrExample.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
0644CEC11DADCD02002E586F /* PopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0644CEC01DADCD02002E586F /* PopupViewController.swift */; };
11+
068A1D081E13212000883454 /* CustomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068A1D071E13212000883454 /* CustomAnimation.swift */; };
1112
069265831DD0F9AD00B67915 /* MainTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 069265821DD0F9AD00B67915 /* MainTableViewController.swift */; };
1213
069265851DD12CF400B67915 /* ExampleTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 069265841DD12CF400B67915 /* ExampleTableViewCell.swift */; };
1314
06A1F0B41CF3D17E0057C79B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06A1F0B31CF3D17E0057C79B /* AppDelegate.swift */; };
@@ -32,6 +33,7 @@
3233

3334
/* Begin PBXFileReference section */
3435
0644CEC01DADCD02002E586F /* PopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopupViewController.swift; sourceTree = "<group>"; };
36+
068A1D071E13212000883454 /* CustomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAnimation.swift; sourceTree = "<group>"; };
3537
069265821DD0F9AD00B67915 /* MainTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainTableViewController.swift; sourceTree = "<group>"; };
3638
069265841DD12CF400B67915 /* ExampleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleTableViewCell.swift; sourceTree = "<group>"; };
3739
06A1F0B01CF3D17E0057C79B /* PresentrExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PresentrExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -82,6 +84,7 @@
8284
069265821DD0F9AD00B67915 /* MainTableViewController.swift */,
8385
069265841DD12CF400B67915 /* ExampleTableViewCell.swift */,
8486
0644CEC01DADCD02002E586F /* PopupViewController.swift */,
87+
068A1D071E13212000883454 /* CustomAnimation.swift */,
8588
06A1F0B71CF3D17E0057C79B /* Main.storyboard */,
8689
06A1F0BA1CF3D17E0057C79B /* Assets.xcassets */,
8790
06A1F0BC1CF3D17E0057C79B /* LaunchScreen.storyboard */,
@@ -236,6 +239,7 @@
236239
069265851DD12CF400B67915 /* ExampleTableViewCell.swift in Sources */,
237240
06A1F0B41CF3D17E0057C79B /* AppDelegate.swift in Sources */,
238241
0644CEC11DADCD02002E586F /* PopupViewController.swift in Sources */,
242+
068A1D081E13212000883454 /* CustomAnimation.swift in Sources */,
239243
);
240244
runOnlyForDeploymentPostprocessing = 0;
241245
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// CustomAnimation.swift
3+
// PresentrExample
4+
//
5+
// Created by Daniel Lozano Valdés on 12/27/16.
6+
// Copyright © 2016 danielozano. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Presentr
11+
12+
class CustomAnimation: PresentrAnimation {
13+
14+
override var springDamping: CGFloat {
15+
return 500
16+
}
17+
18+
override var initialSpringVelocity: CGFloat {
19+
return 1
20+
}
21+
22+
override var animationDuration: TimeInterval {
23+
return 1
24+
}
25+
26+
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
27+
return CGRect(x: 0, y: 0, width: 10, height: 10)
28+
}
29+
30+
}

0 commit comments

Comments
 (0)