How can I get CGRect of tapped rectangle in ScrollView?

164 Views Asked by At

enter image description here

Hello, I want to know the CGRect(coordinates and width/height) of dynamic size rectangle which user tapped in ScrollView.

Is there any way to get this?

1

There are 1 best solutions below

0
On

If you have added UITapGestureRecognizer in every view then you can get the tapped view frame as -

@objc func tapFunction(gesture: UITapGestureRecognizer) {
    let viewFrame = gesture.view.frame
    let height = viewFrame.height  //for height
}

You need to add gesture in every view with a parameter.

let tap = UITapGestureRecognizer(target: self, action: #selector(tapFunction(gesture:)))
yourView.addGestureRecognizer(tap)