Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
55178cf
Update TransitionButton.swift
skhye05 Oct 24, 2018
debaa35
Update TransitionButton.swift
skhye05 Oct 24, 2018
192ab27
Update TransitionButton.swift
skhye05 Oct 24, 2018
4f3929f
Update TransitionButton.swift
skhye05 Oct 24, 2018
dc48e74
Update TransitionButton.swift
skhye05 Oct 24, 2018
c19f251
Update TransitionButton.swift
skhye05 Oct 24, 2018
a377c78
Update TransitionButton.swift
skhye05 Oct 24, 2018
7878757
Update TransitionButton.swift
skhye05 Oct 24, 2018
15b1b7b
Update TransitionButton.swift
skhye05 Oct 24, 2018
ff97dd8
Update TransitionButton.swift
skhye05 Nov 9, 2018
ee8166d
Using constants for CAMediaTimingFunction and CAFillMode
dcoletto Feb 4, 2019
393fe65
Constants for CAMediaTimingFunction and CAFillMode
dcoletto Feb 4, 2019
4d6a59f
* added cachedBounds property for after stopping animation
Feb 5, 2019
9ed5f04
Swift 5.0
hslightnin Apr 27, 2019
0d9d330
1. Migrated code base to Swift 5.0
savana10 Jul 18, 2019
dd37f5d
1. Updated pod version
savana10 Jul 18, 2019
5a1ddd6
Merge pull request #1 from skhye05/master
wowansm Oct 24, 2019
8063317
Merge pull request #2 from dcoletto/master
wowansm Oct 24, 2019
9cbb0e2
Merge pull request #3 from MoldaB/master
wowansm Oct 24, 2019
8fe6a44
Merge pull request #4 from hslightnin/master
wowansm Oct 24, 2019
a7f10b7
- Resolve Conflicts
wowansm Oct 24, 2019
d960014
Merge pull request #6 from wowansm/downapp-feature-updateToSwift5
wowansm Oct 24, 2019
c47175b
- Resolve error
wowansm Oct 24, 2019
3b7537b
- Update version
wowansm Oct 24, 2019
8a154d3
Merge remote-tracking branch 'origin/master'
wowansm Oct 24, 2019
768de53
Update TransitionButton.podspec
wowansm Oct 24, 2019
2acc6e6
- Fix Cached title
wowansm Oct 24, 2019
4176662
Update TransitionButton.podspec
wowansm Oct 24, 2019
a7a6486
Merge remote-tracking branch 'refs/remotes/origin/master'
wowansm Oct 24, 2019
529eeaa
- add isAnimation property
wowansm Oct 24, 2019
b2fb545
Update TransitionButton.podspec
wowansm Oct 24, 2019
2f20d54
- remove private from isAnimation
wowansm Oct 24, 2019
a6c204d
Merge remote-tracking branch 'refs/remotes/origin/master'
wowansm Oct 24, 2019
837b89f
- set public isAnimation property
wowansm Oct 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Source/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>0.5.2</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
4 changes: 2 additions & 2 deletions Source/SpinerLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class SpinerLayer: CAShapeLayer {
rotate.fromValue = 0
rotate.toValue = Double.pi * 2
rotate.duration = 0.4
rotate.timingFunction = CAMediaTimingFunction(name: .linear)
rotate.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)

rotate.repeatCount = HUGE
rotate.fillMode = .forwards
rotate.fillMode = CAMediaTimingFillMode.forwards
rotate.isRemovedOnCompletion = false
self.add(rotate, forKey: rotate.keyPath)

Expand Down
29 changes: 18 additions & 11 deletions Source/TransitionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Stop animation style of the `TransitionButton`.
- expand: expand the button and cover all the screen, useful to do transit animation.
- shake: revert the button to original state and make a shaoe animation, useful to reflect that something went wrong
*/
public enum StopAnimationStyle {
@objc public enum StopAnimationStyle:Int{
case normal
case expand
case shake
Expand Down Expand Up @@ -51,6 +51,8 @@ public enum StopAnimationStyle {
}
}

@IBInspectable open var finishAnimationDuration = 0.4

private lazy var spiner: SpinerLayer = {
let spiner = SpinerLayer(frame: self.frame)
self.layer.addSublayer(spiner)
Expand All @@ -59,9 +61,11 @@ public enum StopAnimationStyle {

private var cachedTitle: String?
private var cachedImage: UIImage?
private var cachedBounds: CGRect!
public var isAnimation: Bool = false

private let springGoEase:CAMediaTimingFunction = CAMediaTimingFunction(controlPoints: 0.45, -0.36, 0.44, 0.92)
private let shrinkCurve:CAMediaTimingFunction = CAMediaTimingFunction(name: .linear)
private let shrinkCurve:CAMediaTimingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
private let expandCurve:CAMediaTimingFunction = CAMediaTimingFunction(controlPoints: 0.95, 0.02, 1, 0.05)
private let shrinkDuration: CFTimeInterval = 0.1

Expand Down Expand Up @@ -93,10 +97,12 @@ public enum StopAnimationStyle {
/**
start animating the button, before starting a task, exemple: before a network call.
*/
open func startAnimation() {
@objc open func startAnimation() {
self.isUserInteractionEnabled = false // Disable the user interaction during the animation
self.cachedTitle = title(for: .normal) // cache title before animation of spiner
self.cachedImage = image(for: .normal) // cache image before animation of spiner
self.cachedBounds = bounds
self.isAnimation = true

self.setTitle("", for: .normal) // place an empty string as title to display a spiner
self.setImage(nil, for: .normal) // remove the image, if any, before displaying the spinner
Expand All @@ -117,9 +123,10 @@ public enum StopAnimationStyle {
- Parameter completion: a callback closure to be called once the animation finished, it may be useful to transit to another view controller, example transit to the home screen from the login screen.

*/
open func stopAnimation(animationStyle:StopAnimationStyle = .normal, revertAfterDelay delay: TimeInterval = 1.0, completion:(()->Void)? = nil) {
@objc open func stopAnimation(animationStyle:StopAnimationStyle = .normal, revertAfterDelay delay: TimeInterval = 1.0, completion:(()->Void)? = nil) {

let delayToRevert = max(delay, 0.2)
self.isAnimation = false

switch animationStyle {
case .normal:
Expand Down Expand Up @@ -151,7 +158,7 @@ public enum StopAnimationStyle {
NSValue(cgPoint: CGPoint(x: CGFloat(point.x + 10), y: CGFloat(point.y))),
NSValue(cgPoint: point)]

keyFrame.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
keyFrame.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
keyFrame.duration = 0.7
self.layer.position = point

Expand All @@ -166,7 +173,7 @@ public enum StopAnimationStyle {
private func setOriginalState(completion:(()->Void)?) {
self.animateToOriginalWidth(completion: completion)
self.spiner.stopAnimation()
self.setTitle(self.cachedTitle, for: .normal)
self.setTitle(cachedTitle, for: .normal)
self.setImage(self.cachedImage, for: .normal)
self.isUserInteractionEnabled = true // enable again the user interaction
self.layer.cornerRadius = self.cornerRadius
Expand All @@ -175,10 +182,10 @@ public enum StopAnimationStyle {
private func animateToOriginalWidth(completion:(()->Void)?) {
let shrinkAnim = CABasicAnimation(keyPath: "bounds.size.width")
shrinkAnim.fromValue = (self.bounds.height)
shrinkAnim.toValue = (self.bounds.width)
shrinkAnim.toValue = self.cachedBounds.width
shrinkAnim.duration = shrinkDuration
shrinkAnim.timingFunction = shrinkCurve
shrinkAnim.fillMode = .forwards
shrinkAnim.fillMode = CAMediaTimingFillMode.forwards
shrinkAnim.isRemovedOnCompletion = false

CATransaction.setCompletionBlock {
Expand All @@ -195,7 +202,7 @@ public enum StopAnimationStyle {
shrinkAnim.toValue = frame.height
shrinkAnim.duration = shrinkDuration
shrinkAnim.timingFunction = shrinkCurve
shrinkAnim.fillMode = .forwards
shrinkAnim.fillMode = CAMediaTimingFillMode.forwards
shrinkAnim.isRemovedOnCompletion = false

layer.add(shrinkAnim, forKey: shrinkAnim.keyPath)
Expand All @@ -208,7 +215,7 @@ public enum StopAnimationStyle {
expandAnim.fromValue = 1.0
expandAnim.toValue = max(expandScale,26.0)
expandAnim.timingFunction = expandCurve
expandAnim.duration = 0.4
expandAnim.duration = finishAnimationDuration
expandAnim.fillMode = .forwards
expandAnim.isRemovedOnCompletion = false

Expand All @@ -230,7 +237,7 @@ public enum StopAnimationStyle {


public extension UIImage {
public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
let rect = CGRect(origin: .zero, size: size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
color.setFill()
Expand Down
2 changes: 1 addition & 1 deletion TransitionButton.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TransitionButton'
s.version = '0.5.2'
s.version = '0.6.3'
s.summary = 'UIButton sublass for loading and transition animation.'

s.description = <<-DESC
Expand Down
21 changes: 10 additions & 11 deletions TransitionButton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,23 @@
TargetAttributes = {
D93F1C971EAEDB6E009A7474 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
D93F1CA01EAEDB6E009A7474 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = D93F1C921EAEDB6E009A7474 /* Build configuration list for PBXProject "TransitionButton" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = D93F1C8E1EAEDB6E009A7474;
productRefGroup = D93F1C991EAEDB6E009A7474 /* Products */;
Expand Down Expand Up @@ -377,12 +378,12 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 0.6.3;
PRODUCT_BUNDLE_IDENTIFIER = com.itechnodev.TransitionButton;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -400,11 +401,11 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 0.6.3;
PRODUCT_BUNDLE_IDENTIFIER = com.itechnodev.TransitionButton;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -417,8 +418,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.itechnodev.TransitionButtonTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -431,8 +431,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.itechnodev.TransitionButtonTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
1 change: 1 addition & 0 deletions iOS Example/Source/FirstViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class FirstViewController: UIViewController {

@IBAction func buttonAction(_ button: TransitionButton) {
button.startAnimation() // 2: Then start the animation when the user tap the button
button.finishAnimationDuration = 0.6
let qualityOfServiceClass = DispatchQoS.QoSClass.background
let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
backgroundQueue.async(execute: {
Expand Down
15 changes: 8 additions & 7 deletions iOS Example/iOS Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,22 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0940;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = ITechnoDev;
TargetAttributes = {
D93F1CBF1EAEDD3F009A7474 = {
CreatedOnToolsVersion = 8.3.2;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = D93F1CBB1EAEDD3F009A7474 /* Build configuration list for PBXProject "iOS Example" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -181,6 +182,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -241,6 +243,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -306,8 +309,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.itechnodev.iOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -326,8 +328,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.itechnodev.iOS-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0940"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down