MarkPW
MarkPW

Reputation: 140

Disabling the nav bar when user back swipes on iOS using Xamarin Forms

Currently i have a class which disables the user from using the backswipe gesture to go back to the previous page on the iOS platform, this code works but the Navigation Side bar still appears when the user does the backswipe gesture, is their a way to disable this feature as well.

My current code stopping backswipe:

 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;



    }
}
}

Upvotes: 0

Views: 528

Answers (2)

Himanshu Dwivedi
Himanshu Dwivedi

Reputation: 8124

You need to set IsGestureEnabled="false" in you Xaml code of MasterDetailPage like this:

<?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>

Upvotes: 1

Gerald Versluis
Gerald Versluis

Reputation: 34118

To disable the swipe gesture on a MasterDetail view you can simply use the IsGestureEnabled property. See: https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.masterdetailpage.isgestureenabled?view=xamarin-forms

Upvotes: 0

Related Questions