当用户使用Xamarin Forms在iOS上滑动时禁用导航栏

问题描述 投票:0回答:2

目前我有一个类禁止用户使用反向扫描手势返回到iOS平台上的上一页,此代码可以正常工作,但导航侧栏仍然会在用户执行反向扫描手势时出现,是他们的一种禁用方式这个功能也是如此。

我当前的代码停止反向擦除:

 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 != null && ViewController.NavigationController != null)
            ViewController.NavigationController.InteractivePopGestureRecognizer.Enabled = false;



    }
}
}
xamarin xamarin.forms
2个回答
1
投票

您需要在MasterDetailPage的Xaml代码中设置IsGestureEnabled="false",如下所示:

<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" 
                  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                  xmlns:views="clr-namespace:Sample.Views" 
                  x:Class="Sample.Views.MainPage"
                  IsGestureEnabled="false">
    <MasterDetailPage.Master>
        <views:MenuPage />
    </MasterDetailPage.Master>
    <MasterDetailPage.Detail>
        <NavigationPage>
            <x:Arguments>
                <views:ItemsPage />
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

0
投票

要在MasterDetail视图上禁用滑动手势,您只需使用IsGestureEnabled属性即可。见:https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.masterdetailpage.isgestureenabled?view=xamarin-forms

© www.soinside.com 2019 - 2024. All rights reserved.