
How about if you need to scale, pan and rotate gesture to an image in your native IOS application. GestureRecognizer is used to introduce gesture in your application. Basic three of the gestures which we are going to discuss,
- RotationGestureRecognizer
- PinchGestureRecognizer
- PanGestureRecognizer
Lets take an example of a UIImage in our case and apply all these gestures to that Image.
RotationGestureRecognizer:
- rotateGesture = new UIRotationGestureRecognizer((() =>
- {
- if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2))
{ - imageView.Transform = CGAffineTransform.MakeRotation(rotateGesture.Rotation + r);
- }
- else if (rotateGesture.State == UIGestureRecognizerState.Ended)
- {
- r += rotateGesture.Rotation;
- }
- }));
- pinchGesture = new UIPinchGestureRecognizer(() =>
- {
- if (pinchGesture.State == UIGestureRecognizerState.Began || pinchGesture.State == UIGestureRecognizerState.Changed)
- {
- pinchGesture.View.Transform *= CGAffineTransform.MakeScale(pinchGesture.Scale, pinchGesture.Scale);
- pinchGesture.Scale = 1;
- }
- });
- panGesture = new UIPanGestureRecognizer(() =>
- {
- if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1))
- {
- var p0 = panGesture.LocationInView(View);
- if (dx == 0)
- dx = p0.X - imageView.Center.X;
- if (dy == 0)
- dy = p0.Y - imageView.Center.Y;
- var p1 = new PointF(p0.X - dx, p0.Y - dy);
- imageView.Center = p1;
- }
- else if (panGesture.State == UIGestureRecognizerState.Ended)
- {
- dx = 0;
- dy = 0;
- }
- });
- panGesture.MaximumNumberOfTouches = 2;
- imageView.AddGestureRecognizer(panGesture);
- imageView.AddGestureRecognizer(rotateGesture);
- imageView.AddGestureRecognizer(pinchGesture);

شان محمدPosted Feb 5, 2021, 7:58 AM
Can you provide a source code?
Santhakumar MunuswamyPosted Nov 16, 2015, 11:45 PM
Nice share