This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") | |
} |
This file contains hidden or 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
self.miniCircleView.center = self.getPoint(for: -90) |
This file contains hidden or 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
// 2 | |
let initialPoint = self.getPoint(for: -90) | |
path.move(to: initialPoint) | |
// 3 | |
for angle in -89...0 { path.addLine(to: self.getPoint(for: angle)) } | |
for angle in 1...270 { path.addLine(to: self.getPoint(for: angle)) } |
This file contains hidden or 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
let newCenterX = radius + radius * cos(radian) | |
let newCenterY = radius + radius * sin(radian) |
This file contains hidden or 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
@IBAction func buttonTapped(_ sender: UIButton) { | |
self.circleView.startAnimating() | |
} |
This file contains hidden or 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
private func animate(view: UIView, path: UIBezierPath) { | |
// 1 | |
let animation = CAKeyframeAnimation(keyPath: "position") | |
// 2 | |
animation.path = path.cgPath | |
// 3 | |
animation.repeatCount = 1 |
This file contains hidden or 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
private func getPoint(for angle: Int) -> CGPoint { | |
// 1 | |
let radius = Double(self.circleView.layer.cornerRadius) | |
// 2 | |
let radian = Double(angle) * Double.pi / Double(180) | |
// 3 | |
let newCenterX = radius * cos(radian) | |
let newCenterY = radius * sin(radian) |
This file contains hidden or 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
// MARK: - Animation | |
func startAnimating() { | |
// 1 | |
let path = UIBezierPath() | |
// 2 | |
let initialPoint = self.getPoint(for: 0) | |
path.move(to: initialPoint) |
This file contains hidden or 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
self.clipsToBounds = false | |
self.addSubview(self.circleView) | |
NSLayoutConstraint.activate([ | |
self.circleView.leadingAnchor.constraint(equalTo: self.leadingAnchor), | |
self.circleView.topAnchor.constraint(equalTo: self.topAnchor), | |
self.circleView.trailingAnchor.constraint(equalTo: self.trailingAnchor), | |
self.circleView.bottomAnchor.constraint(equalTo: self.bottomAnchor) | |
]) |
This file contains hidden or 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
override func layoutSubviews() { | |
super.layoutSubviews() | |
self.circleView.layer.cornerRadius = self.circleView.frame.width / 2.0 | |
self.miniCircleView.layer.cornerRadius = self.miniCircleView.frame.width / 2.0 | |
} |