Skip to content

Commit

Permalink
Adds full ability to launch and fill the progress loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
soberman committed Jan 23, 2016
1 parent 04ce2c3 commit d00a4ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
13 changes: 6 additions & 7 deletions ARSLineProgress/ARSLineProgress/ARSLineProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,13 @@ private extension InfiniteLoader {

private final class ProgressLoader: Appearable {

static weak var weakSelf: ProgressLoader?

var backgroundView: UIVisualEffectView
var outerCircle = CAShapeLayer()
var middleCircle = CAShapeLayer()
var innerCircle = CAShapeLayer()
var multiplier: CGFloat = 1.0
var progress: CGFloat = 0.0
static weak var weakSelf: ProgressLoader?

init() {
backgroundView = BlurredBackgroundRect().view
Expand Down Expand Up @@ -244,11 +243,6 @@ private extension ProgressLoader {
}

func incrementCircleRadius() {
if self.progress >= 100 {
ProgressLoader.weakSelf = nil
completed()
return
}
incrementMultiplier()

let viewBounds = backgroundView.bounds
Expand All @@ -261,6 +255,11 @@ private extension ProgressLoader {
self.outerCircle.path = outerPath.CGPath
self.middleCircle.path = middlePath.CGPath
self.innerCircle.path = innerPath.CGPath

if multiplier >= 100 {
ProgressLoader.weakSelf = nil
completed()
}
}

func incrementMultiplier() {
Expand Down
18 changes: 13 additions & 5 deletions ARSLineProgress/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import UIKit

final class ViewController: UIViewController {

var progress:CGFloat = 0.0

@IBAction func showInfiniteLoader(sender: AnyObject) {
ARSLineProgress.show()
Expand All @@ -21,14 +19,24 @@ final class ViewController: UIViewController {
launchTimer()
}

}


// MARK: Helper Demo Methods

private var progress:CGFloat = 0.0

extension ViewController {

private func launchTimer() {
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.7 * Double(NSEC_PER_SEC)));
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.progress += CGFloat(arc4random_uniform(10))
ARSLineProgress.updateWithProgress(self.progress)
progress += CGFloat(arc4random_uniform(10))
ARSLineProgress.updateWithProgress(progress)
self.launchTimer()

if self.progress >= 100 {
if progress >= 100 {
progress = 0
self.hideLoader()
return
}
Expand Down

0 comments on commit d00a4ea

Please sign in to comment.