小智 1
我也遇到了像你一样的类似问题,并且有解决方法。由于滑动视图太敏感,如果拇指稍微移动一点,设备很容易被视为滑动而不是点击。
它可以使用 OnSwipeChanging 事件和 OnSwipeEnded 事件以及公共属性 Offset 来测量滑动的移动距离。每当调用 OnSwipeChanging 事件时,Offset 的值就会不断更新。当用户停止滑动时,OnSwipeEnded 会获取 Offset 的值,并在 Offset 小于特定值时调用点击操作。
XAML
<SwipeView SwipeChanging="OnSwipeChanging" SwipeEnded="OnSwipeEnded">
<SwipeView.LeftItems>
<SwipeItemView>
<Grid WidthRequest="100" />
</SwipeItemView>
</SwipeView.LeftItems>
<SwipeView.RightItems>
<SwipeItemView>
<Grid WidthRequest="100" />
</SwipeItemView>
</SwipeView.RightItems>
<Frame HeightRequest="50">
<Frame.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnTapped" />
</Frame.GestureRecognizers>
</Frame>
</SwipeView>
Run Code Online (Sandbox Code Playgroud)
C#
public partial class TestView : ContentPage
{
public double OffSet { get; set; } = 0
public TestView()
{
InitializeComponent();
}
public void OnSwipeChanging(object sender, SwipeChangingEventArgs args)
{
OffSet = args.Offset;
var swipeView = (Microsoft.Maui.Controls.SwipeView)sender;
if (args.SwipeDirection == SwipeDirection.Left && offSet < -50)
{
//swipe left action here
}
else if (args.SwipeDirection == SwipeDirection.Right && offSet > 50)
{
//swipe right action here
}
}
public void OnSwipeEnded(object sender, SwipeEndedEventArgs args)
{
var swipeView = (SwipeView)sender;
if (offSet < 5 && offSet > -5)
{
//click button action
OnTapped();
}
swipeView.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
740 次 |
| 最近记录: |