-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
SOPKATHON_33-iOS/SOPKATHON_33-iOS/Presentation/Main/View/ProgressView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// ProgressView.swift | ||
// SOPKATHON_33-iOS | ||
// | ||
// Created by 류희재 on 2023/11/26. | ||
// | ||
|
||
import UIKit | ||
|
||
class ProgressView: UIView { | ||
private var circleLayer = CAShapeLayer() | ||
private var progressLayer = CAShapeLayer() | ||
private var startPoint = CGFloat(-0.5 * Double.pi) | ||
private var endPoint = CGFloat(1.5 * Double.pi) | ||
|
||
override func draw(_ rect: CGRect) { | ||
createCircularPath() | ||
} | ||
|
||
func createCircularPath() { | ||
self.backgroundColor = .white | ||
let circularPath = UIBezierPath(arcCenter: .init( | ||
x: self.frame.width / 2.0, | ||
y: self.frame.height / 2.0), | ||
radius: (frame.size.height - 10) / 2.0 , | ||
startAngle: startPoint, | ||
endAngle: endPoint, | ||
clockwise: true | ||
) | ||
circleLayer.path = circularPath.cgPath | ||
circleLayer.fillColor = UIColor.clear.cgColor | ||
circleLayer.lineCap = .round | ||
circleLayer.lineWidth = 15 | ||
circleLayer.strokeStart = 0 | ||
circleLayer.strokeEnd = 1.0 | ||
circleLayer.strokeColor = UIColor.black.withAlphaComponent(0.4).cgColor | ||
layer.addSublayer(circleLayer) | ||
|
||
progressLayer.path = circularPath.cgPath | ||
progressLayer.fillColor = UIColor.clear.cgColor | ||
progressLayer.lineCap = .round | ||
progressLayer.lineWidth = 15 | ||
progressLayer.strokeStart = 0.0 | ||
// progressLayer.strokeEnd = 0.5 | ||
|
||
progressLayer.strokeColor = UIColor.red.cgColor | ||
layer.addSublayer(progressLayer) | ||
} | ||
|
||
func progressAnimation(duration: TimeInterval, value: Double) { | ||
// created circularProgressAnimation with keyPath | ||
|
||
let circularProgressAnimation = CABasicAnimation(keyPath: "strokeEnd") | ||
// set the end time | ||
circularProgressAnimation.duration = duration | ||
circularProgressAnimation.fromValue = 0 | ||
circularProgressAnimation.toValue = value | ||
circularProgressAnimation.fillMode = .forwards | ||
circularProgressAnimation.isRemovedOnCompletion = false | ||
progressLayer.add(circularProgressAnimation, forKey: "progressAnim") | ||
} | ||
} | ||
|
||
|
||
|