Skip to content

Commit

Permalink
Updates code to support Swift 4.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikeyan.g committed Aug 13, 2018
1 parent bf4348a commit 401c717
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
14 changes: 8 additions & 6 deletions EasyAnimation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
TargetAttributes = {
403482531B8E01ED006C3C7C = {
CreatedOnToolsVersion = 6.4;
DevelopmentTeam = B74NE7DB34;
DevelopmentTeamName = "Bakken & Bæck AS";
LastSwiftMigration = 0800;
};
Expand Down Expand Up @@ -343,8 +344,9 @@
4034826B1B8E01ED006C3C7C /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = B74NE7DB34;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -355,15 +357,15 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.easyanimation.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
4034826C1B8E01ED006C3C7C /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = B74NE7DB34;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand All @@ -375,7 +377,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -394,7 +396,7 @@
PRODUCT_NAME = EasyAnimation;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -416,7 +418,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down
8 changes: 4 additions & 4 deletions EasyAnimation/EAAnimationFuture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class EAAnimationFuture: Equatable, CustomStringConvertible {
/* animation properties */
var duration: CFTimeInterval = 0.0
var delay: CFTimeInterval = 0.0
var options: UIViewAnimationOptions = []
var options: UIView.AnimationOptions = []
var animations: (() -> Void)?
var completion: ((Bool) -> Void)?

Expand Down Expand Up @@ -101,20 +101,20 @@ public class EAAnimationFuture: Equatable, CustomStringConvertible {
}

@discardableResult
public func animate(withDuration duration: TimeInterval, delay: TimeInterval, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
public func animate(withDuration duration: TimeInterval, delay: TimeInterval, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
return animateAndChain(withDuration: duration, delay: delay, options: options, animations: animations, completion: completion)
}

@discardableResult
public func animate(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
public func animate(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
let anim = animateAndChain(withDuration: duration, delay: delay, options: options, animations: animations, completion: completion)
self.springDamping = dampingRatio
self.springVelocity = velocity
return anim
}

@discardableResult
public func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
public func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
var options = options

if options.contains(.repeat) {
Expand Down
60 changes: 30 additions & 30 deletions EasyAnimation/EasyAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private class AnimationContext {
var duration: TimeInterval = 1.0
var currentTime: TimeInterval = {CACurrentMediaTime()}()
var delay: TimeInterval = 0.0
var options: UIViewAnimationOptions? = nil
var options: UIView.AnimationOptions? = nil
var pendingAnimations = [PendingAnimation]()

//spring additions
Expand Down Expand Up @@ -110,16 +110,16 @@ private let specializedLayerKeys: [String: [String]] = [
CATextLayer.self.description(): ["fontSize", "foregroundColor"]
]

public extension UIViewAnimationOptions {
public extension UIView.AnimationOptions {
//CA Fill modes
static let fillModeNone = UIViewAnimationOptions(rawValue: 0)
static let fillModeForwards = UIViewAnimationOptions(rawValue: 1024)
static let fillModeBackwards = UIViewAnimationOptions(rawValue: 2048)
static let fillModeBoth = UIViewAnimationOptions(rawValue: 1024 + 2048)
static let fillModeNone = UIView.AnimationOptions(rawValue: 0)
static let fillModeForwards = UIView.AnimationOptions(rawValue: 1024)
static let fillModeBackwards = UIView.AnimationOptions(rawValue: 2048)
static let fillModeBoth = UIView.AnimationOptions(rawValue: 1024 + 2048)

//CA Remove on completion
static let isRemovedOnCompletion = UIViewAnimationOptions(rawValue: 0)
static let isNotRemovedOnCompletion = UIViewAnimationOptions(rawValue: 16384)
static let isRemovedOnCompletion = UIView.AnimationOptions(rawValue: 0)
static let isNotRemovedOnCompletion = UIView.AnimationOptions(rawValue: 16384)
}

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ extension UIView {
}

@objc
class func EA_animate(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIViewAnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?) {
class func EA_animate(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIView.AnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?) {
//create context
let context = AnimationContext()
context.duration = duration
Expand Down Expand Up @@ -240,7 +240,7 @@ extension UIView {
}

@objc
class func EA_animate(withDuration duration: TimeInterval, delay: TimeInterval, options: UIViewAnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?) {
class func EA_animate(withDuration duration: TimeInterval, delay: TimeInterval, options: UIView.AnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?) {

//create context
let context = AnimationContext()
Expand Down Expand Up @@ -348,45 +348,45 @@ extension UIView {

if context.delay > 0.0 {
anim.beginTime = context.currentTime + context.delay
anim.fillMode = kCAFillModeBackwards
anim.fillMode = CAMediaTimingFillMode.backwards
}

//options
if let options = context.options?.rawValue {

if options & UIViewAnimationOptions.beginFromCurrentState.rawValue == 0 { //only repeat if not in a chain
anim.autoreverses = (options & UIViewAnimationOptions.autoreverse.rawValue == UIViewAnimationOptions.autoreverse.rawValue)
anim.repeatCount = (options & UIViewAnimationOptions.repeat.rawValue == UIViewAnimationOptions.repeat.rawValue) ? Float.infinity : 0
if options & UIView.AnimationOptions.beginFromCurrentState.rawValue == 0 { //only repeat if not in a chain
anim.autoreverses = (options & UIView.AnimationOptions.autoreverse.rawValue == UIView.AnimationOptions.autoreverse.rawValue)
anim.repeatCount = (options & UIView.AnimationOptions.repeat.rawValue == UIView.AnimationOptions.repeat.rawValue) ? Float.infinity : 0
}

//easing
var timingFunctionName = kCAMediaTimingFunctionEaseInEaseOut
var timingFunctionName = CAMediaTimingFunctionName.easeInEaseOut

if options & UIViewAnimationOptions.curveLinear.rawValue == UIViewAnimationOptions.curveLinear.rawValue {
if options & UIView.AnimationOptions.curveLinear.rawValue == UIView.AnimationOptions.curveLinear.rawValue {
//first check for linear (it's this way to take up only 2 bits)
timingFunctionName = kCAMediaTimingFunctionLinear
} else if options & UIViewAnimationOptions.curveEaseIn.rawValue == UIViewAnimationOptions.curveEaseIn.rawValue {
timingFunctionName = kCAMediaTimingFunctionEaseIn
} else if options & UIViewAnimationOptions.curveEaseOut.rawValue == UIViewAnimationOptions.curveEaseOut.rawValue {
timingFunctionName = kCAMediaTimingFunctionEaseOut
timingFunctionName = CAMediaTimingFunctionName.linear
} else if options & UIView.AnimationOptions.curveEaseIn.rawValue == UIView.AnimationOptions.curveEaseIn.rawValue {
timingFunctionName = CAMediaTimingFunctionName.easeIn
} else if options & UIView.AnimationOptions.curveEaseOut.rawValue == UIView.AnimationOptions.curveEaseOut.rawValue {
timingFunctionName = CAMediaTimingFunctionName.easeOut
}

anim.timingFunction = CAMediaTimingFunction(name: timingFunctionName)

//fill mode
if options & UIViewAnimationOptions.fillModeBoth.rawValue == UIViewAnimationOptions.fillModeBoth.rawValue {
if options & UIView.AnimationOptions.fillModeBoth.rawValue == UIView.AnimationOptions.fillModeBoth.rawValue {
//both
anim.fillMode = kCAFillModeBoth
} else if options & UIViewAnimationOptions.fillModeForwards.rawValue == UIViewAnimationOptions.fillModeForwards.rawValue {
anim.fillMode = CAMediaTimingFillMode.both
} else if options & UIView.AnimationOptions.fillModeForwards.rawValue == UIView.AnimationOptions.fillModeForwards.rawValue {
//forward
anim.fillMode = (anim.fillMode == kCAFillModeBackwards) ? kCAFillModeBoth : kCAFillModeForwards
} else if options & UIViewAnimationOptions.fillModeBackwards.rawValue == UIViewAnimationOptions.fillModeBackwards.rawValue {
anim.fillMode = (anim.fillMode == CAMediaTimingFillMode.backwards) ? CAMediaTimingFillMode.both : CAMediaTimingFillMode.forwards
} else if options & UIView.AnimationOptions.fillModeBackwards.rawValue == UIView.AnimationOptions.fillModeBackwards.rawValue {
//backwards
anim.fillMode = kCAFillModeBackwards
anim.fillMode = CAMediaTimingFillMode.backwards
}

//is removed on completion
if options & UIViewAnimationOptions.isNotRemovedOnCompletion.rawValue == UIViewAnimationOptions.isNotRemovedOnCompletion.rawValue {
if options & UIView.AnimationOptions.isNotRemovedOnCompletion.rawValue == UIView.AnimationOptions.isNotRemovedOnCompletion.rawValue {
anim.isRemovedOnCompletion = false
} else {
anim.isRemovedOnCompletion = true
Expand All @@ -409,7 +409,7 @@ extension UIView {
:returns: The created request.
*/
public class func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
public class func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {

let currentAnimation = EAAnimationFuture()
currentAnimation.duration = duration
Expand Down Expand Up @@ -440,7 +440,7 @@ extension UIView {
:returns: The created request.
*/
public class func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIViewAnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {
public class func animateAndChain(withDuration duration: TimeInterval, delay: TimeInterval, usingSpringWithDamping dampingRatio: CGFloat, initialSpringVelocity velocity: CGFloat, options: UIView.AnimationOptions, animations: @escaping () -> Void, completion: ((Bool) -> Void)?) -> EAAnimationFuture {

let currentAnimation = EAAnimationFuture()
currentAnimation.duration = duration
Expand Down
2 changes: 1 addition & 1 deletion EasyAnimation/RBBSpringAnimation/RBBSpringAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RBBSpringAnimation: CAKeyframeAnimation {
mass = 1
stiffness = 100

calculationMode = kCAAnimationDiscrete
calculationMode = CAAnimationCalculationMode.discrete
}

required init(coder aDecoder: NSCoder) {
Expand Down

0 comments on commit 401c717

Please sign in to comment.