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

编程入门 行业动态 更新时间:2024-10-27 21:21:59
本文介绍了如何在嵌入式 UIImagePickerController 中隐藏导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试将 UIImagePickerController 作为普通 UIViewController 中的子视图呈现.

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

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

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:

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

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

但是,我想完全删除导航栏.我试图在 ViewWillAppearViewDidLoad<中调用 SetNavigationBarHidden(true, true);NavigationController.SetNavigationBarHidden(true, true);/code> 和自定义图像选择器控制器的 ViewDidAppear,但没有结果.

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.

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

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);
    }

推荐答案

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

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);

它会正常工作

这篇关于如何在嵌入式 UIImagePickerController 中隐藏导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 02:38:49,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌入式   如何在   UIImagePickerController

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!