使用 xamarin 表单从页面中删除向后滑动手势

Mar*_*kPW 2 xamarin xamarin.forms

有没有办法在我的项目的一个页面上禁用 iOS 的向后滑动到上一页选项?

Ger*_*uis 8

您可以通过实现自定义渲染器并为此设置正确的属性来实现此目的。您可以在下面看到示例实现。InteractivePopGestureRecognizer在这种情况下,您需要将正确的属性设置为 false。

ViewWillAppear在初始化时执行此操作NavigationController

using DisableSwipe.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(ContentPage), typeof(NoBackSwipeRenderer))]
namespace DisableSwipe.iOS
{
    public class NoBackSwipeRenderer : PageRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (ViewController?.NavigationController != null)
                ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = false;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)