I've tried to make swipe gesture for user swipe to left and right.
Fortunately, I found a useful example in Professional iPhone Programming with MonoTouch and .NET/C# chapter page 292 Recognizing Gestures and this article. However, when I run this code in simulator, nothing happens. What did is I miss?
Please could you help me to make this work?
The code that I used can be downloaded by the following link. http://www.7749tutor.com/code/iPad06.zip Please, have a look at line 31 of MyViewController.cs file
Looking forward to hearin开发者_C百科g from you.
I made this much easier class extension method to a UIView instance: View Extension
You use it like:
View.Swipe(UISwipeGestureRecognizerDirection.Right).Event += (s, r) =>
new UIAlertView("Swipe Test", "Swipe " + r.Direction.ToString(), null, "Ok")
.Show();
No longer do you have to add ugly code to your projects for swipes!
This is how I do it in one of my views:
(inside my class definition)
public static Selector RightSwipeSelector
{
get
{
return new Selector("HandleRightSwipe");
}
}
public class SwipeRecogniserDelegate : UIGestureRecognizerDelegate
{
public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
return true;
}
}
[Export("HandleRightSwipe")]
public void HandleRightSwipe(UISwipeGestureRecognizer recogniser)
{
Debug.WriteLine("Got a right swipe.");
}
(inside ViewDidLoad)
UISwipeGestureRecognizer sgrRight=new UISwipeGestureRecognizer();
sgrRight.AddTarget(this,RightSwipeSelector);
sgrRight.Direction=UISwipeGestureRecognizerDirection.Right;
sgrRight.Delegate=new SwipeRecogniserDelegate();
View.AddGestureRecognizer(sgrRight);
精彩评论