Commit 4b7269bf by Dmitriy Stepanets

Finished sun animation

parent fb34be35
...@@ -48,7 +48,6 @@ class CitySunCell: UITableViewCell { ...@@ -48,7 +48,6 @@ class CitySunCell: UITableViewCell {
private let maxUvLabel = UILabel() private let maxUvLabel = UILabel()
//Computed //Computed
private var dashLinePath = UIBezierPath()
private var earthCircleSegment:CircleSegment { private var earthCircleSegment:CircleSegment {
return .init(chord: earthImageView.frame.width, return .init(chord: earthImageView.frame.width,
height: earthImageView.frame.height) height: earthImageView.frame.height)
...@@ -74,7 +73,6 @@ class CitySunCell: UITableViewCell { ...@@ -74,7 +73,6 @@ class CitySunCell: UITableViewCell {
super.layoutSubviews() super.layoutSubviews()
drawDashLine() drawDashLine()
updateSunPosition()
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
...@@ -82,35 +80,44 @@ class CitySunCell: UITableViewCell { ...@@ -82,35 +80,44 @@ class CitySunCell: UITableViewCell {
} }
private func drawDashLine() { private func drawDashLine() {
infographicDashLine.path = dashLinePath(progress: 1.0).cgPath
}
private func dashLinePath(progress:CGFloat) -> UIBezierPath {
var pathProgress = max(0, progress)
pathProgress = min(1, pathProgress)
let segment = dashCircleSegment let segment = dashCircleSegment
let start = -(.pi - segment.alpha) let start = -(.pi - segment.alpha)
let end = -segment.alpha let end = -segment.alpha
let percent = (start - end) * 0.4 let percent = (start - end) * pathProgress
dashLinePath = UIBezierPath(arcCenter: .init(x: infographicContainer.frame.width / 2, let path = UIBezierPath(arcCenter: .init(x: earthImageView.center.x,
y: earthImageView.frame.origin.y + segment.radius - kDashLineTopInset), y: earthImageView.frame.origin.y + segment.radius - kDashLineTopInset),
radius: segment.radius, radius: segment.radius,
startAngle: start, startAngle: start,
endAngle: start - percent, endAngle: start - percent,
clockwise: true) clockwise: true)
infographicDashLine.path = dashLinePath.cgPath return path
} }
@objc private func handleArrowButton() {
}
//Public
public func updateSunPosition() { public func updateSunPosition() {
sunImageView.layer.removeAllAnimations() sunImageView.layer.removeAnimation(forKey: "sun.position")
sunImageView.frame.origin = .init(x: 20 - sunImageView.frame.width / 2, sunImageView.frame.origin = .init(x: 20 - sunImageView.frame.width / 2,
y: infographicContainer.frame.height - sunImageView.frame.height / 2) y: infographicContainer.frame.height - sunImageView.frame.height / 2)
let animation = CAKeyframeAnimation(keyPath: "position") let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = self.dashLinePath.cgPath animation.path = self.dashLinePath(progress: 0.7).cgPath
animation.calculationMode = .paced animation.calculationMode = .paced
animation.duration = 2 animation.duration = 1.3
animation.rotationMode = .rotateAuto animation.rotationMode = .rotateAuto
animation.isRemovedOnCompletion = true animation.isRemovedOnCompletion = false
sunImageView.layer.add(animation, forKey: nil) animation.fillMode = .forwards
} sunImageView.layer.add(animation, forKey: "sun.position")
@objc private func handleArrowButton() {
} }
} }
...@@ -176,7 +183,7 @@ private extension CitySunCell { ...@@ -176,7 +183,7 @@ private extension CitySunCell {
infographicContainer.addSubview(earthImageView) infographicContainer.addSubview(earthImageView)
earthImageView.snp.makeConstraints { (make) in earthImageView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview().inset(37) make.centerX.equalToSuperview()
make.bottom.equalToSuperview() make.bottom.equalToSuperview()
} }
......
...@@ -34,6 +34,14 @@ class TodayViewController: UIViewController { ...@@ -34,6 +34,14 @@ class TodayViewController: UIViewController {
prepareTableView() prepareTableView()
} }
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate { _ in
self.tableView.reloadData()
}
}
@objc private func handleCityButton() { @objc private func handleCityButton() {
print("Handle city button") print("Handle city button")
} }
......
...@@ -18,19 +18,24 @@ ...@@ -18,19 +18,24 @@
<key>orderHint</key> <key>orderHint</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
<key>Localize-Swift.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>Pods-1Weather.xcscheme</key> <key>Pods-1Weather.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>2</integer> <integer>1</integer>
</dict> </dict>
<key>SnapKit.xcscheme</key> <key>SnapKit.xcscheme</key>
<dict> <dict>
<key>isShown</key> <key>isShown</key>
<false/> <false/>
<key>orderHint</key> <key>orderHint</key>
<integer>3</integer> <integer>2</integer>
</dict> </dict>
</dict> </dict>
<key>SuppressBuildableAutocreation</key> <key>SuppressBuildableAutocreation</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment