スワイプgesture recognizerをXamarin Forms for windows phone(8.1 & 10)プラットフォームに最適に実装する方法は?Xamarinフォームのスワイプジェスチャー認識ツールWindows phone(8.1&10)プラットフォーム
renderersのAndroidとiOSプラットフォームの例がたくさんあります。しかし、WinRTやUWPのためではありません。
スワイプgesture recognizerをXamarin Forms for windows phone(8.1 & 10)プラットフォームに最適に実装する方法は?Xamarinフォームのスワイプジェスチャー認識ツールWindows phone(8.1&10)プラットフォーム
renderersのAndroidとiOSプラットフォームの例がたくさんあります。しかし、WinRTやUWPのためではありません。
AndroidおよびiOSプラットフォーム用のレンダラの例がたくさんあります。しかし、WinRTやUWPのためではありません。
現在、Xamarin.Formsにはこのような「SwipeGestureRecognizer」APIはありません。しかし、あなたはカスタムSwipeGestureRecognizer
PanGestureRecognizer
をベースにすることができます。私は "SwipeGestureRecognizer"をシミュレートするための次のコードを書いています。しかし、私が使ったスレッショルドは、実際のテストではなく、あなたの要件に基づいてスレッショルドを変更することができます。
public enum SwipeDeriction
{
Left = 0,
Rigth,
Above,
Bottom
}
public class SwipeGestureReconginzer : PanGestureRecognizer
{
public delegate void SwipeRequedt(object sender, SwipeDerrictionEventArgs e);
public event EventHandler<SwipeDerrictionEventArgs> Swiped;
public SwipeGestureReconginzer()
{
this.PanUpdated += SwipeGestureReconginzer_PanUpdated;
}
private void SwipeGestureReconginzer_PanUpdated(object sender, PanUpdatedEventArgs e)
{
if (e.TotalY > -5 | e.TotalY < 5)
{
if (e.TotalX > 10)
{
Swiped(this, new SwipeDerrictionEventArgs(SwipeDeriction.Rigth));
}
if (e.TotalX < -10)
{
Swiped(this, new SwipeDerrictionEventArgs(SwipeDeriction.Left));
}
}
if (e.TotalX > -5 | e.TotalX < 5)
{
if (e.TotalY > 10)
{
Swiped(this, new SwipeDerrictionEventArgs(SwipeDeriction.Bottom));
}
if (e.TotalY < -10)
{
Swiped(this, new SwipeDerrictionEventArgs(SwipeDeriction.Above));
}
}
}
}
public class SwipeDerrictionEventArgs : EventArgs
{
public SwipeDeriction Deriction { get; }
public SwipeDerrictionEventArgs(SwipeDeriction deriction)
{
Deriction = deriction;
}
}
MainPage.xaml.cs
var swipe = new SwipeGestureReconginzer();
swipe.Swiped += Tee_Swiped;
TestLabel.GestureRecognizers.Add(swipe);
private void Tee_Swiped(object sender, SwipeDerrictionEventArgs e)
{
switch (e.Deriction)
{
case SwipeDeriction.Above:
{
}
break;
case SwipeDeriction.Left:
{
}
break;
case SwipeDeriction.Rigth:
{
}
break;
case SwipeDeriction.Bottom:
{
}
break;
default:
break;
}
}
私はまだこのアプローチをテストすることができていない - しかし、私は本当にそれが好き。私は、ほとんどのUIコントロールにスワイプジェスチャーサポートを追加することができるかもしれませんが、UIレンダラーを記述する必要はありません。 – Ada
私が見ることができる唯一の注意点は、スワイプが完了したときにのみイベントを検出して起動する機能ですが、スレッショルドとタイマーの周りを少し微調整すれば、それを管理できると思います。ありがとう:) – Ada