降低SwipeView敏感性.net Maui

发布于 2025-02-07 20:29:58 字数 275 浏览 0 评论 0原文

我不想necro an 旧帖子所以我在此创建了一个新的。我有一个CollectionView在两侧都有两个按钮来增加或减少计数,但是按钮可以工作,但是它们很难触发,因为我的SwipeView左右项目在尝试点击按钮时一直在触发。每3-5次尝试按下按钮,是否有一种方法可以调整在SwipeView激活之前必须水平滑动的多远?

I didn't want to necro an old post so I am creating a new one on this. I have a collectionview that has two buttons on either side to increment or decrement a count, the buttons work however they are a lot harder to trigger since my swipeview left and right items keep triggering while trying to tap the buttons. This happens every 3-5 times attempting to hit the buttons, is there a way to adjust how far you have to swipe horizontally before swipeview activates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零崎曲识 2025-02-14 20:29:59

我还遇到了类似的问题,并为这些问题带来了解决方法。由于SwipeView过于敏感,并且如果拇指移动一点,则可以轻松地将设备算作滑动而不是点击。

它可以使用Onswipechanging事件和Onswipeended事件,而公共财产可抵消,以测量滑动的移动距离。偏移的价值是每当调用OnswipeChanging事件时继续更新。当用户停止刷卡时,如果偏移量小于特定值,则onswipeended会取出偏移值并调用TAP操作。

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>

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();
    }
}

I also faced a similar problem like you and have a workaround for the issues. Since that the swipeview is too sensitive and device easily count as swipe not tap if the thumb move a little bit.

It can use the OnSwipeChanging event and OnSwipeEnded event with a public property Offset on measuring the moving distance of the swipe. The value of Offset is keep updating whenever the OnSwipeChanging event is invoked. When the user has stopped swiping, the OnSwipeEnded take the value of Offset and invoke tap action if Offset is less than a specific value.

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>

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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文