diff --git a/Images/Gradient.gif b/Images/Gradient.gif new file mode 100644 index 0000000..cfde356 Binary files /dev/null and b/Images/Gradient.gif differ diff --git a/InDeterminate/Gradient.swift b/InDeterminate/Gradient.swift new file mode 100644 index 0000000..aa63cce --- /dev/null +++ b/InDeterminate/Gradient.swift @@ -0,0 +1,79 @@ +// +// Gradient.swift +// ProgressKit +// +// Created by Sam on 11/9/18. +// Copyright © 2018 Kauntey Suryawanshi. All rights reserved. +// + +import Foundation +import Cocoa + +@IBDesignable +open class Gradient: IndeterminateAnimation { + + + static let progressAnimationKey = "GradientAnimation" + private let gradientLayer = CAGradientLayer() + private let gradientView = NSView() + + /// Duration for the progress animation. + var progressAnimationDuration: TimeInterval = 5.0 + + /// Colors used for the gradient. + var gradientColorList: [NSColor] = [NSColor.red, NSColor.green, NSColor.blue, NSColor.orange, NSColor.purple] + + + override func notifyViewRedesigned() { + super.notifyViewRedesigned() + + + } + + override func configureLayers() { + super.configureLayers() + + gradientView.frame = CGRect(x: 0, y: 0, width: bounds.size.width, height: bounds.size.height) + gradientView.wantsLayer = true + addSubview(gradientView) + + setupGradientLayer() + } + + private func setupGradientLayer() { + gradientLayer.frame = CGRect(x: 0, y: 0, width: 3 * bounds.size.width, height: bounds.size.height) + gradientLayer.position = .zero + + gradientLayer.anchorPoint = .zero + + gradientLayer.startPoint = .zero + gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.0) + + var reversedColorList = Array(gradientColorList.reversed()) + reversedColorList.removeFirst() + reversedColorList.removeLast() + + let infinteColorList = gradientColorList + reversedColorList + gradientColorList + gradientLayer.colors = infinteColorList.map({ $0.cgColor }) + + gradientView.layer?.insertSublayer(gradientLayer, at: 0) + } + //MARK: Indeterminable protocol + override func startAnimation() { + let animation = CABasicAnimation(keyPath: "position") + + animation.fromValue = CGPoint(x: -2 * bounds.size.width, y: 0) + animation.toValue = CGPoint.zero + animation.duration = progressAnimationDuration + animation.repeatCount = Float.infinity + + // Prevent stopping animation on disappearing view, and then coming back. + animation.isRemovedOnCompletion = false + + gradientLayer.add(animation, forKey: Gradient.progressAnimationKey) + } + + override func stopAnimation() { + gradientLayer.removeAnimation(forKey: Gradient.progressAnimationKey) + } +} diff --git a/ProgressKit.xcodeproj/project.pbxproj b/ProgressKit.xcodeproj/project.pbxproj index 2eb629c..c9ebe9f 100644 --- a/ProgressKit.xcodeproj/project.pbxproj +++ b/ProgressKit.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4C580088219531CE00A1D8B9 /* Gradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C580087219531CE00A1D8B9 /* Gradient.swift */; }; E31617A61BC0596C007AD70F /* BaseView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E31617A51BC0596C007AD70F /* BaseView.swift */; }; E340FDB81BDE45F000CE6550 /* RotatingArc.swift in Sources */ = {isa = PBXBuildFile; fileRef = E340FDB71BDE45F000CE6550 /* RotatingArc.swift */; }; E35D1C6C1B676889001DBAF2 /* Spinner.swift in Sources */ = {isa = PBXBuildFile; fileRef = E35D1C6B1B676889001DBAF2 /* Spinner.swift */; }; @@ -37,6 +38,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 4C580087219531CE00A1D8B9 /* Gradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Gradient.swift; path = InDeterminate/Gradient.swift; sourceTree = ""; }; E310B1D21D7AB2D4008DEF62 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; }; E310B1D41D7AB2EA008DEF62 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = SOURCE_ROOT; }; E31617A51BC0596C007AD70F /* BaseView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseView.swift; sourceTree = ""; }; @@ -91,6 +93,7 @@ E3918F831B4E88DE00558DAB /* ShootingStars.swift */, E35D1C6B1B676889001DBAF2 /* Spinner.swift */, E340FDB71BDE45F000CE6550 /* RotatingArc.swift */, + 4C580087219531CE00A1D8B9 /* Gradient.swift */, ); name = Indeterminate; sourceTree = ""; @@ -276,6 +279,7 @@ E3918F851B4E88DE00558DAB /* ShootingStars.swift in Sources */, E3918F811B4E88CF00558DAB /* CircularProgressView.swift in Sources */, E35D1C6C1B676889001DBAF2 /* Spinner.swift in Sources */, + 4C580088219531CE00A1D8B9 /* Gradient.swift in Sources */, E3918F841B4E88DE00558DAB /* MaterialProgress.swift in Sources */, E3AD65D81B426758009541CD /* AppDelegate.swift in Sources */, E37568DF1B6AAB530073E26F /* ProgressBar.swift in Sources */, diff --git a/ProgressKit/Base.lproj/Main.storyboard b/ProgressKit/Base.lproj/Main.storyboard index cf37393..3f484ed 100644 --- a/ProgressKit/Base.lproj/Main.storyboard +++ b/ProgressKit/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - - + + - + + + @@ -649,11 +651,14 @@ - - + + + + + @@ -675,9 +680,12 @@ - + + + + @@ -691,15 +699,15 @@ - + - + - + @@ -723,14 +731,14 @@ - + - + @@ -753,7 +761,7 @@ - + @@ -770,8 +778,26 @@ + + + + + + + + + + + + + + + + + + - + @@ -801,7 +827,7 @@ - + @@ -1072,7 +1098,7 @@ - + @@ -1415,7 +1441,7 @@ - +