Commit f6a6422b by Demid Merzlyakov

Fix moon cell layout on the iPad.

parent 710d5e60
...@@ -9,7 +9,8 @@ import UIKit ...@@ -9,7 +9,8 @@ import UIKit
class MoonPhaseCell: UITableViewCell { class MoonPhaseCell: UITableViewCell {
//Private //Private
private let kCircleInset:CGFloat = 55 private let kCircleInsetX: CGFloat = 55
private let kCircleInsetY: CGFloat = 32
private let headingLabel = UILabel() private let headingLabel = UILabel()
private let headingButton = ArrowButton() private let headingButton = ArrowButton()
private let container = UIView() private let container = UIView()
...@@ -54,14 +55,23 @@ class MoonPhaseCell: UITableViewCell { ...@@ -54,14 +55,23 @@ class MoonPhaseCell: UITableViewCell {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
var pathCenter: CGPoint {
CGPoint(x: baseLine.frame.origin.x + baseLine.bounds.width / 2, y: baseLine.frame.origin.y)
}
var pathRadius: CGFloat {
let center = pathCenter
return min(center.x - kCircleInsetX, center.y - kCircleInsetY)
}
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
let center = CGPoint(x: baseLine.frame.origin.x + baseLine.bounds.width / 2, y: baseLine.frame.origin.y) let center = pathCenter
let radius = center.x - kCircleInset let radius = pathRadius
//Gradient //Gradient
circleGradientLayer.frame = .init(x: kCircleInset - 4, circleGradientLayer.frame = .init(x: center.x - radius - 4,
y: center.y - radius - 4, y: center.y - radius - 4,
width: (radius * 2) + 8, width: (radius * 2) + 8,
height: radius + 4) height: radius + 4)
...@@ -99,8 +109,8 @@ class MoonPhaseCell: UITableViewCell { ...@@ -99,8 +109,8 @@ class MoonPhaseCell: UITableViewCell {
let start:CGFloat = -.pi let start:CGFloat = -.pi
let end:CGFloat = 0 let end:CGFloat = 0
let percent = (start - end) * pathProgress let percent = (start - end) * pathProgress
let center = CGPoint(x: baseLine.frame.origin.x + baseLine.bounds.width / 2, y: baseLine.frame.origin.y) let center = pathCenter
let radius = center.x - kCircleInset let radius = pathRadius
let path = UIBezierPath(arcCenter: center, let path = UIBezierPath(arcCenter: center,
radius: radius, radius: radius,
...@@ -163,9 +173,12 @@ class MoonPhaseCell: UITableViewCell { ...@@ -163,9 +173,12 @@ class MoonPhaseCell: UITableViewCell {
public func updateMoonPosition() { public func updateMoonPosition() {
contentView.layoutIfNeeded() contentView.layoutIfNeeded()
let center = pathCenter
let radius = pathRadius
moonImageView.layer.removeAnimation(forKey: "moon.position") moonImageView.layer.removeAnimation(forKey: "moon.position")
moonImageView.frame.origin = .init(x: kCircleInset - moonImageView.frame.width / 2, moonImageView.frame.origin = .init(x: center.x - radius - moonImageView.frame.width / 2,
y: baseLine.frame.origin.y - moonImageView.frame.height) y: center.y - moonImageView.frame.height)
let animation = CAKeyframeAnimation(keyPath: "position") let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = self.moonPath(progress: moonProgress).cgPath animation.path = self.moonPath(progress: moonProgress).cgPath
......
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