How to hide Navigation Bar in embedded UIImagePick

2019-08-25 06:34发布

I'm trying to present UIImagePickerController as a subview in ordinary UIViewController.

The problem I'm facing is that I'm unable to hide the inner navigation bar (with "Chwile" title and "Anuluj" button). It looks something like this:

iphone screenshot

I tried subclassing UIImagePickerController with my custom controller. I also tried to style the NavigationBar property and achieved the following result:

enter image description here

However, I'd like to remove the Navigation Bar entirely. I tried to call SetNavigationBarHidden(true, true); and NavigationController.SetNavigationBarHidden(true, true); in ViewWillAppear, ViewDidLoad and also ViewDidAppear of custom image picker controller, but with no result.

Do you know how to remove the nav bar entirely? The solution in swift or obj-c is also perfect for me.

    private void PresentImagePicker(UIImagePickerControllerSourceType type)
    {
        imagePicker = new CustomImagePickerController
        {
            SourceType = type,
            AllowsEditing = false,
        };

        imagePicker.FinishedPickingMedia += OnImagePickerFinishedPickingMedia;
        imagePicker.Canceled += OnImagePickerCancelled;

        AddChildViewController(imagePicker);

        ContentView.AddSubview(imagePicker.View);
        imagePicker.View.Frame = Content.Bounds;
        imagePicker.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

        imagePicker.DidMoveToParentViewController(this);
    }

1条回答
Lonely孤独者°
2楼-- · 2019-08-25 07:10

Instead of adding subview to parent view and managing frames, you can simply use presentViewController like this:

self.present(imagePicker, animated: true, completion: nil)

So, you need to remove following these lines and replace them with just one line as above:

        AddChildViewController(imagePicker);
        ContentView.AddSubview(imagePicker.View);
        imagePicker.View.Frame = Content.Bounds;
        imagePicker.View.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

        imagePicker.DidMoveToParentViewController(this);

and it will work fine

查看更多
登录 后发表回答