Hi fullstackdev,
To expand on the above answers, the EntityGestureRecognizer
can be utilized and handled like any other that conforms to UIGestureRecognizer
. When you add gestures to your ARView
for your entity, you can add an objc function as its target, and access the gesture's states. Please consider the following code:
arView.installGestures(.all, for: clonedEntity).forEach { entityGesture in
entityGesture.addTarget(self, action: #selector(handleEntityGesture(_:)))
}
Then our target function would look something like this:
@objc func handleEntityGesture(_ sender: UIGestureRecognizer) {
// Scale
if let scaleGesture = sender as? EntityScaleGestureRecognizer {
switch scaleGesture.state {
case .began:
// Handle things that happen when gesture begins
case .changed:
// Handle things during the gesture
case .ended:
// Handle things when the gesture has ended
default:
return
}
}
}
In the .ended
case, you can grab the entity's scale like so, and do whatever you want with it. If you need to store it somewhere, consider passing it into some other type of function:
case .ended:
let scale = scaleGesture.entity?.transform.scale
// Do what you want with the scale...
You can also access the other gesture recognizers by casting the gesture as either EntityTranslationGestureRecognizer
, or EntityRotationGestureRecognizer
and access their states similarly like the above.
Hope this helps.