Commit f6a6422b by Demid Merzlyakov

Fix moon cell layout on the iPad.

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