0
我有一個iOS和UWP的Xamarin表單項目,已經實現了主細節佈局,並且它在兩個平臺上都很棒,但是如果我們從左側滑動,iOS會顯示主頁面(漢堡菜單),但是在UWP我們需要點擊菜單圖標才能打開母版頁,如何啓用刷機功能來在UWP上顯示母版頁?如何啓用滑動手勢將Xamarin形式的母版頁形式UWP?
我有一個iOS和UWP的Xamarin表單項目,已經實現了主細節佈局,並且它在兩個平臺上都很棒,但是如果我們從左側滑動,iOS會顯示主頁面(漢堡菜單),但是在UWP我們需要點擊菜單圖標才能打開母版頁,如何啓用刷機功能來在UWP上顯示母版頁?如何啓用滑動手勢將Xamarin形式的母版頁形式UWP?
目前,Xamarin.Forms中沒有這樣的「SwipeGestureRecognizer」api。但你可以根據PanGestureRecognizer
定製SwipeGestureRecognizer
。我編寫了下面的代碼來模擬「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;
}
}
謝謝你試試這個。 –