【问题标题】:PanGestureRecognizer inside ListView (Xamarin.Forms)ListView 内的 PanGestureRecognizer (Xamarin.Forms)
【发布时间】:2018-07-19 05:48:38
【问题描述】:

我正在 Xamarin.Forms(Android 和 iOS)中制作消息传递应用程序。

消息显示在ListView

现在我想添加一个新功能。当我将消息气球拖到一边时,它会显示消息信息。

用户按住消息,向右或向左拖动。

  • 如果他拖得足够多,则会显示一个包含信息的新页面
  • 如果他在此“阈值”之前释放,气球会弹回原位

我尝试在气球上使用PanGestureRecognizer(在此上下文中为 PGR)来实现这一点,但它只能部分工作。

安卓

我可以在阈值之前拖动,释放,释放,它可以工作!但是,如果我在水平拖动的同时垂直拖动,ListView“窃取”平移手势,PGR“忘记”它并且不返回任何事件。所以气球就一直呆在那里,稍微靠边一点。

-- 初始状态。

-- 向右拖动消息

-- 我已经发布了消息,但它还在右边。

如果我松开手指而不向下拖动,则不会发生这种情况。

它可能看起来很明显:“为什么不让它在手指被“遗忘”时让它回去?
因为当问题发生时,它不会产生另一个事件。 (并且ListView 没有Scrolled 事件作为ScrollView

iOS

当我尝试使用 PGR 时,ListView 不起作用。但侧拖有效。看起来 PGR 总是首先抓住平移手势。

有什么方法可以让 PGR 和ListView 同时工作?

【问题讨论】:

  • 您要推送一个新页面来显示此信息或类似 ListView 的Context Actions 的地方吗?请张贴一些图片来说明您的要求。
  • @LandLu-MSFT 截图和编辑我的帖子,等等
  • @LandLu-MSFT 完成
  • 你有没有找到解决这个问题的方法?我遇到了完全相同的事情,ListView 正在窃取我的触摸事件,我找不到检测何时发生这种情况的方法。
  • @Mort 抱歉,我没找到。我什至不再使用 Xamarin 了

标签: android ios listview xamarin.forms uipangesturerecognizer


【解决方案1】:

对于 iOS,您可以尝试添加:

Application.Current.On<iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(true)

参考:https://github.com/xamarin/Xamarin.Forms/issues/2299#issuecomment-399578363 https://docs.microsoft.com/ru-ru/xamarin/xamarin-forms/platform/ios/application-pan-gesture

对于 Android,我使用计时器做了一个解决方法:

private System.Threading.Timer timer;

private void PanGesture_PanUpdated(object sender, PanUpdatedEventArgs e)
{
  var statusType = e.StatusType;

  if (statusType != GestureStatus.Started && timer == null)
  {
      // after gesture was broken down, next event will be with wrong 
      // status, like the gesture is continues. So, reset status to Started,
      // consider it is new gesture:
      statusType = GestureStatus.Started;
  }

  var slidingView = yourView;

  switch (statusType)
  {
      case GestureStatus.Started:
          // do any initializations..
          timer = new System.Threading.Timer(_ => {
              finishTranslation(slidingView);
          });
          break;
      case GestureStatus.Running:
          {
              // do any animations..
              timer.Change(TimeSpan.FromMilliseconds(100), TimeSpan.Zero);
          }
          break;
  }
}

private void finishTranslation(View slidingView)
{
  timer = null;
  // finish your animation
}

但是点击手势的问题仍然存在((

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-23
    • 2020-02-08
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多