-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom waiting animation for async crop (#284)
- Loading branch information
1 parent
dd47a13
commit 7800c07
Showing
6 changed files
with
86 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// CustomWaitingIndicator.swift | ||
// MantisExample | ||
// | ||
// Created by Yingtao Guo on 2/24/23. | ||
// Copyright © 2023 Echo. All rights reserved. | ||
// | ||
|
||
import Mantis | ||
import UIKit | ||
|
||
class CustomWaitingIndicator: UIView, Mantis.ActivityIndicatorProtocol { | ||
|
||
private let circleLayer = CAShapeLayer() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setupViews() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
setupViews() | ||
} | ||
|
||
private func setupViews() { | ||
let circlePath = UIBezierPath(ovalIn: bounds) | ||
|
||
circleLayer.path = circlePath.cgPath | ||
circleLayer.strokeColor = UIColor.blue.cgColor | ||
circleLayer.lineWidth = 2 | ||
circleLayer.fillColor = UIColor.clear.cgColor | ||
circleLayer.strokeEnd = 0.25 | ||
circleLayer.frame = bounds | ||
|
||
layer.addSublayer(circleLayer) | ||
} | ||
|
||
func startAnimating() { | ||
circleLayer.removeAllAnimations() | ||
let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z") | ||
rotationAnimation.duration = 1 | ||
rotationAnimation.fromValue = 0 | ||
rotationAnimation.toValue = CGFloat.pi * 2 | ||
rotationAnimation.repeatCount = .infinity | ||
circleLayer.add(rotationAnimation, forKey: "rotationAnimation") | ||
} | ||
|
||
func stopAnimating() { | ||
circleLayer.removeAnimation(forKey: "rotationAnimation") | ||
} | ||
} | ||
|
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
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