Skip to content

Commit

Permalink
clean up a few swift 3 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnyt committed Nov 9, 2016
1 parent 55decba commit 52ae301
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion AnimationSugar.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "AnimationSugar"
s.version = "1.0.0"
s.version = "1.0.1"
s.summary = "Syntactic sugar for iOS animations."

# This description is used to generate tags and improve search results.
Expand Down
110 changes: 55 additions & 55 deletions Pod/Classes/AnimationSugar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import UIKit

/**
Animate changes to one or more `UIView` objects.

- Parameter duration: The length over which the animation(s) occur.
- Parameter animations: A block containing changes to `UIView` animatable properties.
- Returns An `Animation` object that can be further modified (e.g. changing an
animation curve) or chained with further animations.
*/
public func animate(duration duration: TimeInterval = Animation.defaultAnimationDuration, animations: @escaping () -> ()) -> Animation {
public func animate(duration: TimeInterval = Animation.defaultAnimationDuration, animations: @escaping () -> ()) -> Animation {
return Animation(duration: duration, animations: animations)
}

public class Animation {

private struct Constants {
static let DefaultAnimationDuration: TimeInterval = 0.3
}

public static var defaultAnimationDuration = Constants.DefaultAnimationDuration
private let animations: () -> ()
private let duration: TimeInterval
Expand All @@ -36,10 +36,10 @@ public class Animation {
private var springInitialVelocity: CGFloat?
private var prevAnimation: Animation?
private var nextAnimation: Animation?

/**
Initialize an `Animation` object.

- Parameter duration: The length over which the animation(s) occur
- Parameter animations: A block containing changes to `UIView` animatable properties.
- Parameter startNow: A boolean indicating whether to immediately start the animation
Expand All @@ -48,17 +48,17 @@ public class Animation {
init(duration: TimeInterval, animations: @escaping () -> (), startNow: Bool = true) {
self.duration = duration
self.animations = animations

if (startNow) {
DispatchQueue.main.async {
self.start()
}
}
}

/**
Modify the animation options.

- Parameter option: The option(s) to set. E.g. `.withOption(.AnimationCurveEaseOut)`
- Returns An `Animation` object that can be modified or chained with further animations.
*/
Expand All @@ -68,79 +68,79 @@ public class Animation {
} else {
self.options = option
}

return self
}

/**
Add a delay before an animation begins.

- Parameter delay: The amount of time to delay.
- Returns An `Animation` object to be modified or chained with further animations.
*/
public func withDelay(delay: TimeInterval) -> Animation {
self.delay = delay
return self
}

/**
Set a completion block that runs when the animation has completed.

- Parameter completion: A block of code to run.
- Returns An `Animation` object to be modified or chained with further animations.
*/
public func withCompletion(completion: @escaping (Bool) -> ()) -> Animation {
self.completion = completion
return self
}

/**
Animate using "spring" physics.

- Parameter dampingRatio: The damping ratio for the spring animation as it approaches
its quiescent state.

To smoothly decelerate the animation without oscillation, use a value of 1. Employ
a damping ratio closer to zero to increase oscillation.
- Parameter initialVelocity: The initial spring velocity. For smooth start to the
animation, match this value to the view’s velocity as it was prior to attachment.
A value of 1 corresponds to the total animation distance traversed in one second.

For example, if the total animation distance is 200 points and you want the start of the
animation to match a view velocity of 100 pt/s, use a value of 0.5.
- Returns An `Animation` object to be modified or chained with further animations.
*/
public func withSpring(dampingRatio dampingRatio: CGFloat, initialVelocity: CGFloat) -> Animation {
public func withSpring(dampingRatio: CGFloat, initialVelocity: CGFloat) -> Animation {
self.springDampingRatio = dampingRatio
self.springInitialVelocity = initialVelocity
return self
}

/**
Chain a new animation to begin immediately after a previous animation finishes.

Use this method to prevent excessive nesting of animations inside completion blocks.

- Parameter duration: The length over which the animation occurs.
- Parameter animations: A block containing changes to `UIView` animatable properties.
- Returns An `Animation` object to be modified or chained with further animations
*/
public func thenAnimate(duration duration: TimeInterval = defaultAnimationDuration, animations: @escaping () -> ()) -> Animation {
public func thenAnimate(duration: TimeInterval = defaultAnimationDuration, animations: @escaping () -> ()) -> Animation {
let nextAnimation = Animation(duration: duration, animations: animations, startNow: false)
nextAnimation.prevAnimation = self
self.nextAnimation = nextAnimation

// Run current completion block, then run next animation
let completionBlock = self.completion
self.completion = {
finished in
completionBlock?(finished)
self.nextAnimation?.start()
}

return nextAnimation
}

/**
Start an animation.
*/
Expand All @@ -151,7 +151,7 @@ public class Animation {
if let nextAnimation = self.nextAnimation {
nextAnimation.prevAnimation = nil
}

guard let dampingRatio = springDampingRatio, let initialVelocity = springInitialVelocity else {
UIView.animate(withDuration: duration,
delay: delay,
Expand All @@ -160,7 +160,7 @@ public class Animation {
completion: completion)
return
}

UIView.animate(withDuration: duration,
delay: delay,
usingSpringWithDamping: dampingRatio,
Expand All @@ -175,75 +175,75 @@ public class Animation {
extension UIView {
/**
Translate the view using its `transform` property.

- Parameter tx: Translation distance along the x axis
- Parameter ty: Translation distance along the y axis
*/
public func translate(tx tx: CGFloat = 0, ty: CGFloat = 0) {
public func translate(tx: CGFloat = 0, ty: CGFloat = 0) {
self.transform = self.transform.translatedBy(x: tx, y: ty)
}

/**
Scale the view using its `transform` property.

- Parameter sx: Scale factor in the x dimension
- Parameter xy: Scale factor in the y dimension
*/
public func scale(sx sx: CGFloat, sy: CGFloat) {
public func scale(sx: CGFloat, sy: CGFloat) {
self.transform = self.transform.scaledBy(x: sx, y: sy)
}

/**
Rotate the view using its `transform` property.

- Parameter angle: The angle to rotate in radians
*/
public func rotate(angle angle: CGFloat) {
public func rotate(angle: CGFloat) {
self.transform = self.transform.rotated(by: angle)
}

/**
Translate the view by altering its `frame` property.

- Parameter tx: Translation distance along the x axis
- Parameter ty: Translation distance along the y axis
*/
public func translateFrame(tx tx: CGFloat = 0, ty: CGFloat = 0) {
public func translateFrame(tx: CGFloat = 0, ty: CGFloat = 0) {
var frame = self.frame
frame.origin.x = frame.origin.x + tx
frame.origin.y = frame.origin.y + ty
self.frame = frame
}

/**
Stretch or shring the view using its `frame` property.

- Parameter deltaWidth: The amount to stretch the frame in the x direction
- Parameter deltaHeight: The amount to stretch the frame in the y direction
*/
public func stretchFrame(deltaWidth deltaWidth: CGFloat, deltaHeight: CGFloat) {
public func stretchFrame(deltaWidth: CGFloat, deltaHeight: CGFloat) {
var frame = self.frame
frame.size.width = frame.size.width + deltaWidth
frame.size.height = frame.size.height + deltaHeight
self.frame = frame
}

/**
Resize the view's `frame` property.

- Parameter width: The new width
- Parameter height: The new height
*/
public func resizeFrame(width width: CGFloat, height: CGFloat) {
public func resizeFrame(width: CGFloat, height: CGFloat) {
var frame = self.frame
frame.size.width = width
frame.size.height = height
self.frame = frame
}

/**
Flip the view 180 degrees horizontally (along the y axis)

- Parameter perspectiveDistance: The simulated distance between the observer
and the view, in points. Since the flip is in three dimensions, a perspective
transform is applied. Smaller values will have an exaggerated perspective.
Expand All @@ -253,10 +253,10 @@ extension UIView {
self.layer.transform.m34 = -1.0 / perspectiveDistance
self.layer.transform = CATransform3DRotate(self.layer.transform, CGFloat(M_PI), 0, 1.0, 0)
}

/**
Flip the view 180 degrees vertically (along the x axis)

- Parameter perspectiveDistance: The simulated distance between the observer
and the view, in points. Since the flip is in three dimensions, a perspective
transform is applied. Smaller values will have an exaggerated perspective.
Expand All @@ -266,27 +266,27 @@ extension UIView {
self.layer.transform.m34 = -1.0 / perspectiveDistance
self.layer.transform = CATransform3DRotate(self.layer.transform, CGFloat(M_PI), 1.0, 0, 0)
}

/**
Fade in a view by animating its `alpha`.

- Parameter duration: The duration of the animation
- Returns: An `Animation` that can be chained or altered.
*/
public func fadeIn(duration duration: TimeInterval = Animation.defaultAnimationDuration) -> Animation {
public func fadeIn(duration: TimeInterval = Animation.defaultAnimationDuration) -> Animation {
self.alpha = 0.0
return animate(duration: duration) {
self.alpha = 1.0
}
}

/**
Fade out a view by animating its `alpha`.

- Parameter duration: The duration of the animation
- Returns An `Animation` that can be chained or altered.
*/
public func fadeOut(duration duration: TimeInterval = Animation.defaultAnimationDuration) -> Animation {
public func fadeOut(duration: TimeInterval = Animation.defaultAnimationDuration) -> Animation {
return animate(duration: duration) {
self.alpha = 0.0
}
Expand Down

0 comments on commit 52ae301

Please sign in to comment.