diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Source/Info.plist b/Source/Info.plist index daca151..ec0cc7b 100755 --- a/Source/Info.plist +++ b/Source/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.5.2 + $(MARKETING_VERSION) CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/Source/SpinerLayer.swift b/Source/SpinerLayer.swift index b804b3e..35ac336 100755 --- a/Source/SpinerLayer.swift +++ b/Source/SpinerLayer.swift @@ -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) diff --git a/Source/TransitionButton.swift b/Source/TransitionButton.swift index 0e0a343..6fc88b3 100755 --- a/Source/TransitionButton.swift +++ b/Source/TransitionButton.swift @@ -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 @@ -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) @@ -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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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 { @@ -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) @@ -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 @@ -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() diff --git a/TransitionButton.podspec b/TransitionButton.podspec index d22ddb2..aba9c16 100755 --- a/TransitionButton.podspec +++ b/TransitionButton.podspec @@ -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 diff --git a/TransitionButton.xcodeproj/project.pbxproj b/TransitionButton.xcodeproj/project.pbxproj index dd03b41..2e1bf65 100755 --- a/TransitionButton.xcodeproj/project.pbxproj +++ b/TransitionButton.xcodeproj/project.pbxproj @@ -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 */; @@ -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; }; @@ -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; }; @@ -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; }; @@ -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; }; diff --git a/TransitionButton.xcodeproj/xcshareddata/xcschemes/TransitionButton.xcscheme b/TransitionButton.xcodeproj/xcshareddata/xcschemes/TransitionButton.xcscheme index 931465d..7d40257 100755 --- a/TransitionButton.xcodeproj/xcshareddata/xcschemes/TransitionButton.xcscheme +++ b/TransitionButton.xcodeproj/xcshareddata/xcschemes/TransitionButton.xcscheme @@ -1,6 +1,6 @@