Commit 4b7269bf by Dmitriy Stepanets

Finished sun animation

parent fb34be35
......@@ -48,7 +48,6 @@ class CitySunCell: UITableViewCell {
private let maxUvLabel = UILabel()
//Computed
private var dashLinePath = UIBezierPath()
private var earthCircleSegment:CircleSegment {
return .init(chord: earthImageView.frame.width,
height: earthImageView.frame.height)
......@@ -74,7 +73,6 @@ class CitySunCell: UITableViewCell {
super.layoutSubviews()
drawDashLine()
updateSunPosition()
}
required init?(coder: NSCoder) {
......@@ -82,35 +80,44 @@ class CitySunCell: UITableViewCell {
}
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 start = -(.pi - segment.alpha)
let end = -segment.alpha
let percent = (start - end) * 0.4
dashLinePath = UIBezierPath(arcCenter: .init(x: infographicContainer.frame.width / 2,
let percent = (start - end) * pathProgress
let path = UIBezierPath(arcCenter: .init(x: earthImageView.center.x,
y: earthImageView.frame.origin.y + segment.radius - kDashLineTopInset),
radius: segment.radius,
startAngle: start,
endAngle: start - percent,
clockwise: true)
infographicDashLine.path = dashLinePath.cgPath
return path
}
@objc private func handleArrowButton() {
}
//Public
public func updateSunPosition() {
sunImageView.layer.removeAllAnimations()
sunImageView.layer.removeAnimation(forKey: "sun.position")
sunImageView.frame.origin = .init(x: 20 - sunImageView.frame.width / 2,
y: infographicContainer.frame.height - sunImageView.frame.height / 2)
let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = self.dashLinePath.cgPath
animation.path = self.dashLinePath(progress: 0.7).cgPath
animation.calculationMode = .paced
animation.duration = 2
animation.duration = 1.3
animation.rotationMode = .rotateAuto
animation.isRemovedOnCompletion = true
sunImageView.layer.add(animation, forKey: nil)
}
@objc private func handleArrowButton() {
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
sunImageView.layer.add(animation, forKey: "sun.position")
}
}
......@@ -176,7 +183,7 @@ private extension CitySunCell {
infographicContainer.addSubview(earthImageView)
earthImageView.snp.makeConstraints { (make) in
make.left.right.equalToSuperview().inset(37)
make.centerX.equalToSuperview()
make.bottom.equalToSuperview()
}
......
......@@ -34,6 +34,14 @@ class TodayViewController: UIViewController {
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() {
print("Handle city button")
}
......
......@@ -18,19 +18,24 @@
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Localize-Swift.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>Pods-1Weather.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
<integer>1</integer>
</dict>
<key>SnapKit.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
<integer>2</integer>
</dict>
</dict>
<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