首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >windows (8.1 & 10)平台Xamarin窗体中的滑动手势识别器

windows (8.1 & 10)平台Xamarin窗体中的滑动手势识别器
EN

Stack Overflow用户
提问于 2017-04-21 18:26:23
回答 1查看 1.4K关注 0票数 2

如何最好地在windows (8.1 & 10)平台上实现手势识别器

我看到了很多渲染器的例子,这些例子都适用于安卓和iOS平台。但对WinRT和UWP来说不是。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-24 09:11:37

我看到了很多用于安卓和iOS平台的渲染器的例子。但对WinRT和UWP来说不是。

目前,还没有适用于SwipeGestureRecognizer的“Xamarin.Forms”api。但是您可以在SwipeGestureRecognizer的基础上定制PanGestureRecognizer。我编写了以下模拟"SwipeGestureRecognizer“的代码。但是我使用的阈值只是用于测试,而不是真正的阈值,您可以根据您的需求修改阈值。

代码语言:javascript
复制
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

代码语言:javascript
复制
  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;
      }
  }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43549629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档