Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using UIGestureRecognizer in Xamarin.iOS ref: http://qiita.com/amay077/items/a6754176f2abe339adce
using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Diagnostics;
namespace GesturesSample
{
public partial class GesturesSampleViewController : UIViewController
{
public GesturesSampleViewController() : base ("GesturesSampleViewController", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Tap gesture
this.View.AddGestureRecognizer(new UITapGestureRecognizer(tap =>
{
Debug.WriteLine("Double Tap.");
})
{
NumberOfTapsRequired = 2 // Double tap
});
// Drag(Pan) gesture
this.View.AddGestureRecognizer(new UIPanGestureRecognizer(pan =>
{
var p = pan.TranslationInView(this.View);
var v = pan.VelocityInView(this.View);
Debug.WriteLine("Pan. transration:{0}, velocity:{1}", p, v);
}));
// Pinch gesture
this.View.AddGestureRecognizer(new UIPinchGestureRecognizer(pin =>
{
var scale = pin.Scale;
var v = pin.Velocity;
Debug.WriteLine("Pinch. scale:{0}, velocity:{1}", scale, v);
}));
// Swipe gesture
this.View.AddGestureRecognizer(new UISwipeGestureRecognizer(sw =>
{
Debug.WriteLine("Swipe.");
}));
// Rotate gesture
this.View.AddGestureRecognizer(new UIRotationGestureRecognizer(ro =>
{
var rotation = ro.Rotation;
var v = ro.Velocity;
Debug.WriteLine("Rotate. rotation:{0}, velocity:{1}", rotation, v);
}));
// Long press gesture
this.View.AddGestureRecognizer(new UILongPressGestureRecognizer(lp =>
{
Debug.WriteLine("Long press.");
}));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment