Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
297 views
in Technique[技术] by (71.8m points)

ios - How to hide Navigation Bar in embedded UIImagePickerController

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);
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...