I have two UiViews: skinView (purple) and bottomView (pink). SkinView is above bottomView. Both views are the same size and have the same constraints. skinView has a pan gesture recognizer that only drags up and down by adjusting the center Y constraint. The view will only pan up half way and back down. I added some logic to only pan down while the skinView y origin is less than the bottom view y origin. However, it seems like it drags further down than the bottom view y origin sometimes.
Added some logs and I see the Y origin of the skinView can be off by quite a bit once the pan down is complete:
Skin View y position: 77.0
Bottom View y position: 1.6666666666666856
override func viewDidLoad() {
super.viewDidLoad()
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didPan(_:)))
skinView.addGestureRecognizer(panGestureRecognizer!)
}
@objc private func didPan(_ sender: UIPanGestureRecognizer) {
let height = self.skinView.frame.size.height/2
let skinViewBottomY = self.skinView.frame.origin.y + self.skinView.frame.size.height
let bottomViewBottomY = self.bottomView.frame.origin.y + self.bottomView.frame.size.height
if panGestureRecognizer!.state == .began {
print("Pan started")
} else if panGestureRecognizer!.state == .changed {
let translation = panGestureRecognizer!.translation(in: self.skinView)
if (translation.y < 0 && skinViewBottomY >= bottomViewBottomY/2) {
self.verticalConstraint?.constant += translation.y
panGestureRecognizer!.setTranslation(.zero, in: self.skinView)
print("UP")
} else if (translation.y > 0 && self.skinView.frame.origin.y < self.bottomView.frame.origin.y) {
self.verticalConstraint?.constant += translation.y
panGestureRecognizer!.setTranslation(.zero, in: self.skinView)
print("DOWN")
}
}
}



