Skip to content

Commit

Permalink
add points and animate to point
Browse files Browse the repository at this point in the history
  • Loading branch information
SoyArpad committed Apr 18, 2017
1 parent e9a009e commit c8ed75b
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 96 deletions.
4 changes: 2 additions & 2 deletions CircularStepProgressView.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CircularStepProgressView'
s.version = '1.1.0'
s.version = '1.5.0'
s.summary = 'Circular Progress View with Steps'

s.description = <<-DESC
Expand All @@ -10,7 +10,7 @@ This progress view allows you to mark a progress into a circular line with N ste
s.homepage = 'https://github.com/webuildyouridea/CircularStepProgressView'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Arpad Larrinaga' => '[email protected]' }
s.source = { :git => 'https://github.com/webuildyouridea/CircularStepProgressView.git', :tag => 'v1.1.0' }
s.source = { :git => 'https://github.com/webuildyouridea/CircularStepProgressView.git', :tag => 'v1.5.0' }

s.ios.deployment_target = '8.3'
s.source_files = 'CircularStepProgressView/CircularStepProgressView.swift'
Expand Down
2 changes: 1 addition & 1 deletion CircularStepProgressView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
646079824FC1FF602F8E262C /* [CP] Embed Pods Frameworks */ = {
Expand Down
46 changes: 44 additions & 2 deletions CircularStepProgressView/CircularStepProgressView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CircularStepProgressView: UIView {
var completeLayer: CAShapeLayer!
var circlePoints:[CAShapeLayer] = []
var pointDuration: CFTimeInterval = 0.4
var points: Int = 0
public var points: Int = 0
public var steps: Int = 10 {
didSet {
drawSteps()
Expand Down Expand Up @@ -193,7 +193,7 @@ public class CircularStepProgressView: UIView {
return points
}

func addPoint() {
public func addPoint() {
guard points < steps else {
return
}
Expand All @@ -213,6 +213,48 @@ public class CircularStepProgressView: UIView {

}

public func animate(toStep step: Int) {
let fillStrokeAnimation = POPBasicAnimation(propertyNamed: kPOPShapeLayerStrokeEnd)!
fillStrokeAnimation.duration = pointDuration
fillStrokeAnimation.fromValue = 0
fillStrokeAnimation.toValue = progressPoint * CGFloat(step)
fillStrokeAnimation.removedOnCompletion = false
fillStrokeAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
progressLayer.pop_add(fillStrokeAnimation, forKey: "FillStrokeAnimation")

progress = progressPoint * CGFloat(step)
points = step

animateCircles(toStep: step)
}

func animateCircles(toStep step: Int) {
let circleDuration = pointDuration / CFTimeInterval(step+1)
var begintime = CACurrentMediaTime()
for i in 0..<step {
let pointLayer = circlePoints[i]
begintime = begintime + circleDuration
let fillColorAnimation = POPBasicAnimation(propertyNamed: kPOPShapeLayerFillColor)!
fillColorAnimation.beginTime = begintime
fillColorAnimation.duration = 0.001
fillColorAnimation.removedOnCompletion = false
fillColorAnimation.fromValue = circleColor.cgColor
fillColorAnimation.toValue = fillColor.cgColor
fillColorAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

let strokeColorAnimation = POPBasicAnimation(propertyNamed: kPOPShapeLayerStrokeColor)!
strokeColorAnimation.beginTime = begintime
strokeColorAnimation.duration = 0.001
strokeColorAnimation.removedOnCompletion = false
strokeColorAnimation.fromValue = backColor.cgColor
strokeColorAnimation.toValue = fillColor.cgColor
strokeColorAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

pointLayer.pop_add(fillColorAnimation, forKey: "FillCircle")
pointLayer.pop_add(strokeColorAnimation, forKey: "FillStroke")
}
}

func animateProgressBar() {
let fillStrokeAnimation = POPBasicAnimation(propertyNamed: kPOPShapeLayerStrokeEnd)!
fillStrokeAnimation.duration = pointDuration
Expand Down
4 changes: 2 additions & 2 deletions CircularStepProgressView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.0</string>
<string>1.5.6</string>
<key>CFBundleVersion</key>
<string>14</string>
<string>16</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
7 changes: 6 additions & 1 deletion CircularStepProgressView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ViewController: UIViewController {
super.viewDidLoad()
loadSteps()
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
circleView.animate(toStep: 8)
}

func loadSteps() {
circleView = CircularStepProgressView(frame: CGRect(x: 0,
Expand All @@ -32,7 +37,7 @@ class ViewController: UIViewController {

view.addSubview(circleView)

startTimer()
//startTimer()
}

func addPoint(_ timer: Timer) {
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '8.3'

target 'CircularStepProgressView' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ DEPENDENCIES:
SPEC CHECKSUMS:
pop: f667631a5108a2e60d9e8797c9b32ddaf2080bce

PODFILE CHECKSUM: b0371e2034d6834237659fe5c457274d89fcad00
PODFILE CHECKSUM: b316e79356e279b670b47fc936a4762751012ad1

COCOAPODS: 1.1.1
COCOAPODS: 1.2.1
4 changes: 2 additions & 2 deletions Pods/Manifest.lock

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

Loading

0 comments on commit c8ed75b

Please sign in to comment.