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

标签 ios swift xamarin xamarin.ios uinavigationcontroller

我试图将 UIImagePickerController 呈现为普通 UIViewController 中的 subview 。

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

iphone screenshot

我尝试使用我的自定义 Controller 子类化 UIImagePickerController。我还尝试设置 NavigationBar 属性的样式并取得了以下结果:

enter image description here

但是,我想完全删除导航栏。我试图在 ViewWillAppear 中调用 SetNavigationBarHidden(true, true);NavigationController.SetNavigationBarHidden(true, true);ViewDidLoad 以及自定义图像选择器 Controller 的 ViewDidAppear,但没有结果。

您知道如何完全删除导航栏吗? 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);
    }

最佳答案

无需将 subview 添加到父 View 和管理框架,您可以像这样简单地使用 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);

它会很好地工作

关于ios - 如何在嵌入式 UIImagePickerController 中隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701943/

相关文章:

swift - 获取 Parse 中与当前用户关联的所有结果

swift - Xcode 7.2.1 使用 Swift 按钮制作重置按钮

xamarin - 添加对 Xamarin.Forms 的项目引用

xamarin - UITableViewCell Xamarin.iOs 中的禁用按钮

c# - 如何通过单击标签在 Xamarin.Forms 中调用电话?

ios - 使用 SecItemUpdate 更新钥匙串(keychain) kSecAttrAccessible 返回 -50

ios - 如何合并两个 SwiftyJSON 对象

ios - Cocoa-Touch:如何查看两个 NSDate 是否在同一天?

ios - iOS 中拍照的并发图像处理任务

ios - touchesBegan 在 Swift 中的用法