Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
danlozano committed Dec 27, 2016
2 parents 5397ffd + c6fbc41 commit 7797a48
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Presentr.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Presentr"
s.version = "1.0.5"
s.version = "1.1.0"
s.summary = "A simple Swift wrapper for typical custom view controller presentations."
s.description = <<-DESC
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
Expand All @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.author = { "Daniel Lozano" => "[email protected]" }
s.social_media_url = "http://twitter.com/danlozanov"
s.platform = :ios, "9.0"
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.0.5" }
s.source = { :git => "https://github.com/icalialabs/Presentr.git", :tag => "1.1.0" }
s.source_files = "Presentr/**/*.{swift}"
s.resources = "Presentr/**/*.{xib,ttf}"
end
4 changes: 4 additions & 0 deletions Presentr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
061412091E1316990049FF99 /* SpringFromBottomAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */; };
06686C741CE8248D00F88216 /* PresentrAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C731CE8248D00F88216 /* PresentrAnimation.swift */; };
06686C761CE8250200F88216 /* CoverVerticalFromTopAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */; };
06686C9D1CE947E200F88216 /* CoverHorizontalAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */; };
Expand Down Expand Up @@ -38,6 +39,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpringFromBottomAnimation.swift; sourceTree = "<group>"; };
06686C731CE8248D00F88216 /* PresentrAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresentrAnimation.swift; sourceTree = "<group>"; };
06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoverVerticalFromTopAnimation.swift; sourceTree = "<group>"; };
06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CoverHorizontalAnimation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -86,6 +88,7 @@
06686C731CE8248D00F88216 /* PresentrAnimation.swift */,
06686C9C1CE947E200F88216 /* CoverHorizontalAnimation.swift */,
06686C751CE8250200F88216 /* CoverVerticalFromTopAnimation.swift */,
061412081E1316990049FF99 /* SpringFromBottomAnimation.swift */,
);
name = Animation;
sourceTree = "<group>";
Expand Down Expand Up @@ -294,6 +297,7 @@
buildActionMask = 2147483647;
files = (
06686C761CE8250200F88216 /* CoverVerticalFromTopAnimation.swift in Sources */,
061412091E1316990049FF99 /* SpringFromBottomAnimation.swift in Sources */,
06B5855B1D2D6F8B0045C8DA /* TransitionType.swift in Sources */,
06B5855F1D2D6FE20045C8DA /* ModalCenterPosition.swift in Sources */,
06686C9D1CE947E200F88216 /* CoverHorizontalAnimation.swift in Sources */,
Expand Down
35 changes: 10 additions & 25 deletions Presentr/CoverHorizontalAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,22 @@

import Foundation

/// Custom 'CoverHorizontalAnimation' animation. Conforms to 'PresentrAnimation' protocol
class CoverHorizontalAnimation: NSObject, PresentrAnimation {
class CoverHorizontalAnimation: PresentrAnimation {

var animationDuration: TimeInterval
var fromRight: Bool
private var fromRight: Bool

init(animationDuration: TimeInterval = 0.5, fromRight: Bool = true) {
self.animationDuration = animationDuration
init(fromRight: Bool = true) {
self.fromRight = fromRight
}

}

// MARK: UIViewControllerAnimatedTransitioning

extension CoverHorizontalAnimation: UIViewControllerAnimatedTransitioning {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return animationDuration
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
animate(transitionContext) { finalFrame, containerFrame in
var initialFrame = finalFrame
if self.fromRight {
initialFrame.origin.x = containerFrame.size.width + initialFrame.size.width
} else {
initialFrame.origin.x = 0 - initialFrame.size.width
}
return initialFrame
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
var initialFrame = finalFrame
if fromRight {
initialFrame.origin.x = containerFrame.size.width + initialFrame.size.width
} else {
initialFrame.origin.x = 0 - initialFrame.size.width
}
return initialFrame
}

}
29 changes: 5 additions & 24 deletions Presentr/CoverVerticalFromTopAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,12 @@

import Foundation

/// Custom 'CoverVerticalFromTopAnimation' animation. Conforms to 'PresentrAnimation' protocol
class CoverVerticalFromTopAnimation: NSObject, PresentrAnimation {
class CoverVerticalFromTopAnimation: PresentrAnimation {

var animationDuration: TimeInterval

init(animationDuration: TimeInterval = 0.5) {
self.animationDuration = animationDuration
}

}

// MARK: UIViewControllerAnimatedTransitioning

extension CoverVerticalFromTopAnimation: UIViewControllerAnimatedTransitioning {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return animationDuration
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
animate(transitionContext) { finalFrame, _ in
var initialFrame = finalFrame
initialFrame.origin.y = 0 - initialFrame.size.height
return initialFrame
}
override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
var initialFrame = finalFrame
initialFrame.origin.y = 0 - initialFrame.size.height
return initialFrame
}

}
2 changes: 1 addition & 1 deletion Presentr/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0.4</string>
<string>1.1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
88 changes: 61 additions & 27 deletions Presentr/PresentrAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,61 @@

import Foundation

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

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

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

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

*/
func animate(_ transitionContext: UIViewControllerContextTransitioning, transform: FrameTransformer)
/// Method used to create an initial frame for the animation. Override to customize, default is 0,0,0,0.
///
/// - Parameters:
/// - containerFrame: The container frame.
/// - finalFrame: The final frame for the view controller.
/// - Returns: The initial frame for the animation.
open func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
var initialFrame = finalFrame
initialFrame.origin.y = containerFrame.height + initialFrame.height
return initialFrame
}


/// 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.
///
/// - Parameter transitionContext: The transition context for the transition animation.
/// - Returns: A boolean indicating if you want to use this custom animation instead of the included version.
open func customAnimation(using transitionContext: UIViewControllerContextTransitioning) -> Bool {
return false
}

}

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

extension PresentrAnimation {
extension PresentrAnimation: UIViewControllerAnimatedTransitioning {

public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return animationDuration
}

public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let custom = customAnimation(using: transitionContext)
guard custom == false else {
return
}

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

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

let finalFrameForVC = transitionContext.finalFrame(for: animatingVC!)
let initialFrameForVC = transform(finalFrameForVC, containerView.frame)
let initialFrameForVC = transform(containerFrame: containerView.frame, finalFrame: finalFrameForVC)

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

animatingView?.frame = initialFrame

UIView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 300.0, initialSpringVelocity: 5.0, options: .allowUserInteraction, animations: {

animatingView?.frame = finalFrame

}, completion: { (value: Bool) in
UIView.animate(withDuration: duration,
delay: 0,
usingSpringWithDamping: springDamping,
initialSpringVelocity: initialSpringVelocity,
options: .allowUserInteraction,
animations: {

if !isPresenting {
fromView?.removeFromSuperview()
}
animatingView?.frame = finalFrame

let wasCancelled = transitionContext.transitionWasCancelled
transitionContext.completeTransition(!wasCancelled)
}, completion: { (value: Bool) in

if !isPresenting {
fromView?.removeFromSuperview()
}
let wasCancelled = transitionContext.transitionWasCancelled
transitionContext.completeTransition(!wasCancelled)

})
}

Expand Down
27 changes: 27 additions & 0 deletions Presentr/SpringFromBottomAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// SpringFromBottomAnimation.swift
// PresentrExample
//
// Created by Francesco Perrotti-Garcia on 12/26/16.
// Copyright © 2016 Presentr. All rights reserved.
//

import UIKit

class SpringFromBottomAnimation: PresentrAnimation {

override var springDamping: CGFloat {
return 0.5
}

override var initialSpringVelocity: CGFloat {
return 0
}

override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
var initialFrame = finalFrame
initialFrame.origin.y = containerFrame.size.height + initialFrame.size.height
return initialFrame
}

}
8 changes: 8 additions & 0 deletions Presentr/TransitionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Foundation
- CoverVerticalFromTop: Custom transition animation. Slides in vertically from top.
- CoverHorizontalFromLeft: Custom transition animation. Slides in horizontally from left.
- CoverHorizontalFromRight: Custom transition animation. Slides in horizontally from right.
- Custom: Custom transition animation provided by the user.
*/
public enum TransitionType {

Expand All @@ -28,6 +29,9 @@ public enum TransitionType {
case coverVerticalFromTop
case coverHorizontalFromRight
case coverHorizontalFromLeft
case coverVerticalWithSpring
// User defined
case custom(PresentrAnimation)

/**
Maps the 'TransitionType' to the system provided transition.
Expand Down Expand Up @@ -61,6 +65,10 @@ public enum TransitionType {
return CoverHorizontalAnimation(fromRight: true)
case .coverHorizontalFromLeft:
return CoverHorizontalAnimation(fromRight: false)
case .coverVerticalWithSpring:
return SpringFromBottomAnimation()
case .custom(let animation):
return animation
default:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion PresentrExample/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ platform :ios, '9.0'
use_frameworks!

target 'PresentrExample' do
pod 'Presentr'
pod 'Presentr', :path => '../'
end
4 changes: 4 additions & 0 deletions PresentrExample/PresentrExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

/* Begin PBXFileReference section */
0644CEC01DADCD02002E586F /* PopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopupViewController.swift; sourceTree = "<group>"; };
068A1D071E13212000883454 /* CustomAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomAnimation.swift; sourceTree = "<group>"; };
069265821DD0F9AD00B67915 /* MainTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainTableViewController.swift; sourceTree = "<group>"; };
069265841DD12CF400B67915 /* ExampleTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleTableViewCell.swift; sourceTree = "<group>"; };
06A1F0B01CF3D17E0057C79B /* PresentrExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PresentrExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -82,6 +84,7 @@
069265821DD0F9AD00B67915 /* MainTableViewController.swift */,
069265841DD12CF400B67915 /* ExampleTableViewCell.swift */,
0644CEC01DADCD02002E586F /* PopupViewController.swift */,
068A1D071E13212000883454 /* CustomAnimation.swift */,
06A1F0B71CF3D17E0057C79B /* Main.storyboard */,
06A1F0BA1CF3D17E0057C79B /* Assets.xcassets */,
06A1F0BC1CF3D17E0057C79B /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -236,6 +239,7 @@
069265851DD12CF400B67915 /* ExampleTableViewCell.swift in Sources */,
06A1F0B41CF3D17E0057C79B /* AppDelegate.swift in Sources */,
0644CEC11DADCD02002E586F /* PopupViewController.swift in Sources */,
068A1D081E13212000883454 /* CustomAnimation.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
30 changes: 30 additions & 0 deletions PresentrExample/PresentrExample/CustomAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CustomAnimation.swift
// PresentrExample
//
// Created by Daniel Lozano Valdés on 12/27/16.
// Copyright © 2016 danielozano. All rights reserved.
//

import Foundation
import Presentr

class CustomAnimation: PresentrAnimation {

override var springDamping: CGFloat {
return 500
}

override var initialSpringVelocity: CGFloat {
return 1
}

override var animationDuration: TimeInterval {
return 1
}

override func transform(containerFrame: CGRect, finalFrame: CGRect) -> CGRect {
return CGRect(x: 0, y: 0, width: 10, height: 10)
}

}

0 comments on commit 7797a48

Please sign in to comment.