【问题标题】:Background gesture Recognizer not working for ios in xamarin.forms popup背景手势识别器不适用于 xamarin.forms 弹出窗口中的 ios
【发布时间】:2017-03-24 04:21:46
【问题描述】:

对于 Xamarin.froms,我创建了一个弹出窗口:

我已经使用 ShowPopup 为弹出窗口提供背景,所以如果我点击外部弹出窗口,弹出窗口将被关闭,它在 xamarin.android 中工作正常,但对于 IOS 手势 Rcognizer 用于背景视图,如果我在顶部有一个弹出窗口,则无法正常工作背景视图

<StackLayout x:Name="ShowPopups" Padding="0" BackgroundColor="#99000000" HorizontalOptions="FillAndExpand" IsVisible="{Binding ShowPopup}" VerticalOptions="FillAndExpand">
  <StackLayout.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding OnClosePopupCommand}"  />
  </StackLayout.GestureRecognizers>
</StackLayout>

对于 Xamarin.forms 中的背景弹出窗口..Gesture Recoginizer 对于 android 的背景弹出窗口工作正常,但对于 IOS Command="{Binding OnClosePopupCommand} 没有被调用..任何实现它的建议

【问题讨论】:

    标签: xaml xamarin xamarin.ios xamarin.forms xamarin-studio


    【解决方案1】:

    您可能需要在 UI 线程上运行此命令:

    Device.BeginInvokeOnMainThread(() =>
     { 
       run your OnClosePopupCommand here
     });
    

    【讨论】:

    • 感谢您的解决方案
    【解决方案2】:

    您应该尝试不使用 Xamarin.Forms.Gesture 识别器的 Command 绑定,而是使用 Tapped 事件处理程序。您应该能够轻松地进行这个细微的调整。命令已被弃用,不应继续使用。部分原因是手势在 iOS 和 Android 之间的工作方式不同。

    请务必记住,手势在 Android 和 iOS 之间的处理方式根本不同。 Xamarin.Android 通过使用 IOnGestureListener 来访问必要的覆盖来实现手势,其中 Xamarin.iOS 具有 UIGestureRecognizer 和 UIGestureRecognizerDelegate 来完成类似的操作。

    忽略 Dany DaKur 的回答,因为您的代码将在 UI 线程上运行。可以安全地假设来自 Xamarin 中的 UI 控件事件处理程序(或命令)的第一行代码将在主 UI 线程上执行。这是因为事件处理程序总是从主 UI 线程调用(否则操作系统怎么知道用户点击了手势?)。

    我希望这会有所帮助!

    披露:我为 Xamarin/Microsoft 工作

    【讨论】:

    • 感谢您的解决方案,我会尝试在我的应用中实现它。
    • 我很好奇。您在哪里看到 Command 已被弃用?据我所知,这不是真的!命令只是使用 MVVM 模式处理手势/事件的另一种方式。
    猜你喜欢
    • 2012-09-19
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多