Answer the question
In order to leave comments, you need to log in
How to interact with UIView which is subview of UIScrollView?
There is a UIScrollView, there are several UIViews in it, the movement of which needs to be tracked through touchesMoved (), but the UIScrollView intercepts the touch and does not allow interacting with the UIView.
You need to move both Scroll content and interact with UIView.
How can this be resolved?
Answer the question
In order to leave comments, you need to log in
Try:
var panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(move))
panRecognizer.minimumNumberOfTouches = 1
panRecognizer.maximumNumberOfTouches = 1
panRecognizer.delegate = self
yourView.addGestureRecognizer(panRecognizer)
@objc func move(_ sender: Any) {
if (sender as? UIPanGestureRecognizer)?.state == .changed {
// This will return you location in view
let currentPoint: CGPoint = sender.location(in: view)
// This will return you location in Scrollview
let scrollPoint: CGPoint = sender.location(in: sender.view.superview)
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question