Skip to content
This repository has been archived by the owner on Aug 8, 2020. It is now read-only.

Add Gradient Indeterminate Animation #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added Images/Gradient.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions InDeterminate/Gradient.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions ProgressKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -91,6 +93,7 @@
E3918F831B4E88DE00558DAB /* ShootingStars.swift */,
E35D1C6B1B676889001DBAF2 /* Spinner.swift */,
E340FDB71BDE45F000CE6550 /* RotatingArc.swift */,
4C580087219531CE00A1D8B9 /* Gradient.swift */,
);
name = Indeterminate;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
66 changes: 46 additions & 20 deletions ProgressKit/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11198.2"/>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -649,11 +651,14 @@
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="ProgressKit" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" unifiedTitleAndToolbar="YES"/>
<window key="window" title="ProgressKit" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="206" height="54"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<connections>
<outlet property="delegate" destination="B8D-0N-5wS" id="ItK-CW-Ojy"/>
</connections>
</window>
<connections>
<segue destination="GTh-XG-eDn" kind="relationship" relationship="window.shadowedContentViewController" id="ztZ-rM-59J"/>
Expand All @@ -675,9 +680,12 @@
<rect key="frame" x="0.0" y="0.0" width="321" height="113"/>
<autoresizingMask key="autoresizingMask"/>
<font key="font" metaFont="message"/>
<tabViewItems/>
<connections>
<outlet property="delegate" destination="GTh-XG-eDn" id="ded-jz-llQ"/>
</connections>
</tabView>
<connections>
<outlet property="tabView" destination="nfr-Au-q0a" id="OHt-L1-HI3"/>
<segue destination="XfG-lQ-9wD" kind="relationship" relationship="tabItems" id="nlJ-xP-ZKw"/>
<segue destination="rgo-kk-Wcf" kind="relationship" relationship="tabItems" id="4Yk-6n-yUT"/>
</connections>
Expand All @@ -691,15 +699,15 @@
<objects>
<viewController id="rgo-kk-Wcf" customClass="InDeterminateViewController" customModule="ProgressKit" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" wantsLayer="YES" id="lmx-kT-Si1">
<rect key="frame" x="0.0" y="0.0" width="500" height="184"/>
<rect key="frame" x="0.0" y="0.0" width="500" height="214"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qjG-BT-qLK" customClass="MaterialProgress" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="20" y="84" width="80" height="80"/>
<rect key="frame" x="20" y="114" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8Ph-2H-wiR">
<rect key="frame" x="59" y="59" width="41" height="17"/>
<rect key="frame" x="59" y="89" width="41" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="inline" title="More" bezelStyle="inline" alignment="center" borderStyle="border" inset="2" id="lBv-3R-Zg0">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -710,7 +718,7 @@
</connections>
</button>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3VR-oT-y2I" customClass="Spinner" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="250" y="84" width="80" height="80"/>
<rect key="frame" x="250" y="114" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="size" keyPath="starSize">
Expand All @@ -723,14 +731,14 @@
</userDefinedRuntimeAttributes>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="haM-Vg-aIY" customClass="Crawler" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="129" y="84" width="80" height="80"/>
<rect key="frame" x="129" y="114" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="displayAfterAnimationEnds" value="YES"/>
</userDefinedRuntimeAttributes>
</customView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Npu-8G-HkC">
<rect key="frame" x="168" y="59" width="41" height="17"/>
<rect key="frame" x="168" y="89" width="41" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="inline" title="More" bezelStyle="inline" alignment="center" borderStyle="border" inset="2" id="SqX-Fr-AwH">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -741,7 +749,7 @@
</connections>
</button>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kmB-H3-AT2" customClass="ShootingStars" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="20" y="34" width="438" height="3"/>
<rect key="frame" x="20" y="64" width="438" height="3"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="foreground">
Expand All @@ -753,7 +761,7 @@
</userDefinedRuntimeAttributes>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NfH-n9-vtu" customClass="ShootingStars" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="20" y="11" width="438" height="3"/>
<rect key="frame" x="20" y="41" width="438" height="3"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<shadow key="shadow" blurRadius="1">
<color key="color" red="0.25490197539329529" green="0.63529413938522339" blue="0.87058824300765991" alpha="1" colorSpace="calibratedRGB"/>
Expand All @@ -770,8 +778,26 @@
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zl3-cP-p4r" customClass="Gradient" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="20" y="20" width="438" height="3"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<shadow key="shadow" blurRadius="1">
<color key="color" red="0.25490197539999998" green="0.63529413940000001" blue="0.87058824300000004" alpha="1" colorSpace="calibratedRGB"/>
</shadow>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="foreground">
<color key="value" white="1" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="cornerRadius">
<real key="value" value="0.0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="background">
<color key="value" red="0.25490197539999998" green="0.63529413940000001" blue="0.87058824300000004" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</customView>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Q8N-1B-PXN">
<rect key="frame" x="289" y="59" width="41" height="17"/>
<rect key="frame" x="289" y="89" width="41" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="inline" title="More" bezelStyle="inline" alignment="center" controlSize="small" borderStyle="border" inset="2" id="Z8O-Rd-zkL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -782,7 +808,7 @@
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vs0-Bp-9Zv">
<rect key="frame" x="422" y="59" width="41" height="17"/>
<rect key="frame" x="422" y="89" width="41" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="inline" title="More" bezelStyle="inline" alignment="center" controlSize="small" borderStyle="border" inset="2" id="zgh-wl-Oer">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -793,15 +819,15 @@
</connections>
</button>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lR0-9k-CEu" customClass="RotatingArc" customModule="ProgressKit" customModuleProvider="target">
<rect key="frame" x="378" y="84" width="80" height="80"/>
<rect key="frame" x="378" y="114" width="80" height="80"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</subviews>
</view>
</viewController>
<customObject id="lcO-Gc-g97" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="477" y="228"/>
<point key="canvasLocation" x="477" y="243"/>
</scene>
<!--In Determinate View Controller-->
<scene sceneID="vp2-ly-Hqp">
Expand Down Expand Up @@ -1072,7 +1098,7 @@
</viewController>
<customObject id="qek-pA-X3K" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="804" y="525"/>
<point key="canvasLocation" x="1161" y="683"/>
</scene>
<!--Determinate View Controller-->
<scene sceneID="hIz-AP-VOD">
Expand Down Expand Up @@ -1415,7 +1441,7 @@
</viewController>
<customObject id="aXo-xa-gLk" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="328" y="518.5"/>
<point key="canvasLocation" x="107" y="701"/>
</scene>
<!--In Determinate View Controller-->
<scene sceneID="7yv-As-dUl">
Expand Down