我试图将 UIImagePickerController 呈现为普通 UIViewController 中的 subview 。
我面临的问题是我无法隐藏内部导航栏(带有“Chwile”标题和“Anuluj”按钮)。它看起来像这样:
我尝试使用我的自定义 Controller 子类化 UIImagePickerController。我还尝试设置 NavigationBar 属性的样式并取得了以下结果:
但是,我想完全删除导航栏。我试图在 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/