如何在嵌入式UIImagePickerController中隐藏导航栏

时间:2018-12-10 08:30:18

标签: ios swift xamarin xamarin.ios uinavigationcontroller

我试图将UIImagePickerController作为普通UIViewController中的子视图呈现。

我面临的问题是我无法隐藏内部导航栏(带有“ Chwile”标题和“ Anuluj”按钮)。看起来像这样:

iphone screenshot

我尝试使用自定义控制器将UIImagePickerController子类化。我还尝试设置了NavigationBar属性的样式,并获得了以下结果:

enter image description here

但是,我想完全删除导航栏。我尝试在自定义图片选择器控制器的SetNavigationBarHidden(true, true);NavigationController.SetNavigationBarHidden(true, true);ViewWillAppear中调用ViewDidLoadViewDidAppear,但是没有结果。

您知道如何完全删除导航栏吗? swift或obj-c中的解决方案对我来说也是完美的。

    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 个答案:

答案 0 :(得分:1)

您可以像下面这样简单地使用presentViewController,而不是将子视图添加到父视图和管理框架:

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

因此,您需要删除以下几行,并用上面的一行代替它们:

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

        imagePicker.DidMoveToParentViewController(this);

它将正常工作