[iOS] fix user position tracking in Elevation Profile

This commit is contained in:
Aleksey Belousov 2020-04-06 01:17:51 +03:00 committed by Vladimir Byko-Ianko
parent 3900fe3ac9
commit a2eddc5c77
2 changed files with 11 additions and 6 deletions

View file

@ -18,7 +18,7 @@ class ChartInfoView: UIView {
private let pointInfoView = ChartPointInfoView()
private let pointsView = ChartPointIntersectionView(frame: CGRect(x: 0, y: 0, width: 2, height: 0))
private let myPositionView = ChartMyPositionView(frame: CGRect(x: 50, y: 0, width: 2, height: 0))
private let myPositionView = ChartMyPositionView(frame: CGRect(x: 0, y: 0, width: 2, height: 0))
private var lineInfo: ChartLineInfo?
fileprivate var captured = false {
@ -43,7 +43,6 @@ class ChartInfoView: UIView {
return
}
myPositionView.isHidden = false
myPositionView.center = CGPoint(x: bounds.width * myPositionX, y: myPositionView.center.y)
updateMyPosition()
}
}
@ -122,8 +121,9 @@ class ChartInfoView: UIView {
}
private func updateMyPosition() {
myPositionView.center = CGPoint(x: bounds.width * myPositionX, y: myPositionView.center.y)
guard let (_, myPositionPoints) = delegate?.chartInfoView(self, infoAtPointX: myPositionView.center.x) else { return }
myPositionView.updatePoint(myPositionPoints[0].point.y)
myPositionView.pinY = myPositionPoints[0].point.y
}
@objc func onPan(_ sender: UIPanGestureRecognizer) {

View file

@ -3,6 +3,11 @@ import UIKit
class ChartMyPositionView: UIView {
override class var layerClass: AnyClass { CAShapeLayer.self }
var shapeLayer: CAShapeLayer { layer as! CAShapeLayer }
var pinY: CGFloat = 0 {
didSet {
updatePin()
}
}
fileprivate let pinView = MyPositionPinView(frame: CGRect(x: 0, y: 0, width: 12, height: 16))
@ -28,11 +33,11 @@ class ChartMyPositionView: UIView {
path.addLine(to: CGPoint(x: bounds.width / 2, y: bounds.height))
shapeLayer.path = path.cgPath
pinView.center = CGPoint(x: bounds.midX, y: bounds.midY)
updatePin()
}
func updatePoint(_ y: CGFloat) {
pinView.center = CGPoint(x: bounds.midX, y: y + pinView.bounds.height / 2)
private func updatePin() {
pinView.center = CGPoint(x: bounds.midX, y: pinY + pinView.bounds.height / 2)
}
}