Responding to manipulation gestures
In some cases, an object needs to be manipulated on the screen. This can be done using the stretch action, and the most natural way to do this is to simply use a two-finger pinch gesture.
How to do it...
Adding support for pinch-to-zoom is just a matter of passing the touch events to an instance of ScaleGestureDetector
and implementing the IOnScaleGestureListener
interface:
- To support the pinch-to-zoom gesture, we need to first implement the
ScaleGestureDetector.IOnScaleGestureListener
interface:public class MyView : View, ScaleGestureDetector.IOnScaleGestureListener { public bool OnScaleBegin(ScaleGestureDetector detector) { return true; } public bool OnScale(ScaleGestureDetector detector) { return true; } public void OnScaleEnd(ScaleGestureDetector detector) { } }
- Then, we create an instance of the
ScaleGestureDetector
type:scaleDetector = new ScaleGestureDetector(Context, this);
- Next, we need to override the
OnTouchEvent()
method to...