Skip to content

Commit

Permalink
Merge pull request #25 from kentya6/v1.2.0
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
kentya6 authored Jun 29, 2018
2 parents ba49a10 + 086dd70 commit 022f6b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand Down
3 changes: 2 additions & 1 deletion Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ViewController: UIViewController {
private func configureHalfCircularProgress() {
halfCircularProgress = KYCircularProgress(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height/2), showGuide: true)
let center = CGPoint(x: view.frame.width / 2, y: view.frame.height / 4)
halfCircularProgress.path = UIBezierPath(arcCenter: center, radius: CGFloat((halfCircularProgress.frame).width/3), startAngle: CGFloat(Double.pi), endAngle: CGFloat(0.0), clockwise: true)
halfCircularProgress.path = UIBezierPath(arcCenter: center, radius: CGFloat((halfCircularProgress.frame).width/3), startAngle: 0, endAngle: CGFloat(Double.pi * 2), clockwise: true)
halfCircularProgress.strokeStart = 0.5
halfCircularProgress.colors = [UIColor(rgba: 0xA6E39DAA), UIColor(rgba: 0xAEC1E3AA), UIColor(rgba: 0xAEC1E3AA), UIColor(rgba: 0xF3C0ABAA)]
halfCircularProgress.guideColor = UIColor(red: 0.1, green: 0.1, blue: 0.1, alpha: 0.4)

Expand Down
2 changes: 1 addition & 1 deletion KYCircularProgress.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "KYCircularProgress"
s.version = "1.1.0"
s.version = "1.2.0"
s.summary = "Flexible progress bar written in Swift."
s.homepage = "https://github.com/kentya6/KYCircularProgress"
s.license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $ brew install carthage
To integrate KYCircularProgress into your Xcode project using Carthage, specify it in your `Cartfile`:

```ogdl
github "kentya6/KYCircularProgress" >= 1.1.0
github "kentya6/KYCircularProgress" >= 1.2.0
```

#### Manually
Expand Down
45 changes: 22 additions & 23 deletions Source/KYCircularProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ open class KYCircularProgress: UIView {
*/
@IBInspectable open var progress: Double = 0.0 {
didSet {
let clipProgress = max( min(progress, Double(1.0)), Double(0.0) )
progressView.update(progress: clipProgress)
let clipProgress = max( min( progress, 1.0), 0.0 )
progressView.update(progress: normalize(progress: clipProgress))

progressChanged?(clipProgress, self)
delegate?.progressChanged(progress: clipProgress, circularProgress: self)
Expand Down Expand Up @@ -105,22 +105,22 @@ open class KYCircularProgress: UIView {
}

/**
Progress start angle.
Progress start offset. (0.0 - 1.0)
*/
open var startAngle: Double = 0.0 {
@IBInspectable open var strokeStart: Double = 0.0 {
didSet {
progressView.startAngle = startAngle
guideView.startAngle = startAngle
progressView.shapeLayer.strokeStart = CGFloat(max( min(strokeStart, 1.0), 0.0 ))
guideView.shapeLayer.strokeStart = CGFloat(max( min(strokeStart, 1.0), 0.0 ))
}
}

/**
Progress end angle.
Progress end offset. (0.0 - 1.0)
*/
open var endAngle: Double = 0.0 {
@IBInspectable open var strokeEnd: Double = 1.0 {
didSet {
progressView.endAngle = endAngle
guideView.endAngle = endAngle
progressView.shapeLayer.strokeEnd = CGFloat(max( min(strokeEnd, 1.0), 0.0 ))
guideView.shapeLayer.strokeEnd = CGFloat(max( min(strokeEnd, 1.0), 0.0 ))
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ open class KYCircularProgress: UIView {
self.progressView.radius = self.radius
guideView.shapeLayer.path = self.progressView.shapeLayer.path
guideView.shapeLayer.strokeColor = self.tintColor.cgColor
guideView.update(progress: 1.0)
guideView.update(progress: normalize(progress: 1.0))
return guideView
}()

Expand Down Expand Up @@ -234,8 +234,8 @@ open class KYCircularProgress: UIView {
}

public func set(progress: Double, duration: Double) {
let clipProgress = max( min(progress, Double(1.0)), Double(0.0) )
progressView.update(progress: clipProgress, duration: duration)
let clipProgress = max( min(progress, 1.0), 0.0 )
progressView.update(progress: normalize(progress: clipProgress), duration: duration)

progressChanged?(clipProgress, self)
delegate?.progressChanged(progress: clipProgress, circularProgress: self)
Expand All @@ -248,6 +248,10 @@ open class KYCircularProgress: UIView {
}
}

private func normalize(progress: Double) -> CGFloat {
return CGFloat(strokeStart + progress * (strokeEnd - strokeStart))
}

override open func layoutSubviews() {
super.layoutSubviews()

Expand All @@ -267,8 +271,6 @@ public protocol KYCircularProgressDelegate {

// MARK: - KYCircularShapeView
class KYCircularShapeView: UIView {
var startAngle = 0.0
var endAngle = 0.0
var radius = 0.0
var scale: (x: CGFloat, y: CGFloat) = (1.0, 1.0)

Expand All @@ -292,27 +294,24 @@ class KYCircularShapeView: UIView {
override func layoutSubviews() {
super.layoutSubviews()

if startAngle == endAngle {
endAngle = startAngle + (Double.pi * 2)
}
shapeLayer.path = shapeLayer.path ?? layoutPath().cgPath
var affineScale = CGAffineTransform(scaleX: scale.x, y: scale.y)
shapeLayer.path = shapeLayer.path?.copy(using: &affineScale)
}

private func layoutPath() -> UIBezierPath {
let halfWidth = CGFloat(frame.width / 2.0)
return UIBezierPath(arcCenter: CGPoint(x: halfWidth, y: halfWidth), radius: (frame.width - CGFloat(radius)) / 2, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: true)
return UIBezierPath(arcCenter: CGPoint(x: halfWidth, y: halfWidth), radius: (frame.width - CGFloat(radius)) / 2, startAngle: 0, endAngle: CGFloat(Double.pi * 2), clockwise: true)
}

fileprivate func update(progress: Double) {
fileprivate func update(progress: CGFloat) {
CATransaction.begin()
CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
shapeLayer.strokeEnd = CGFloat(progress)
shapeLayer.strokeEnd = progress
CATransaction.commit()
}

fileprivate func update(progress: Double, duration: Double) {
fileprivate func update(progress: CGFloat, duration: Double) {
CATransaction.begin()
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.duration = duration
Expand All @@ -321,7 +320,7 @@ class KYCircularShapeView: UIView {
animation.toValue = progress
shapeLayer.add(animation, forKey: "animateStrokeEnd")
CATransaction.commit()
shapeLayer.strokeEnd = CGFloat(progress)
shapeLayer.strokeEnd = progress
}
}

Expand Down

0 comments on commit 022f6b1

Please sign in to comment.