在另一个 UIView 中显示 UIImagePickerController

发布于 2024-08-12 03:16:48 字数 471 浏览 2 评论 0原文

过去几个月我一直在使用 UIImagePickerController 进行广泛的工作,特别是 OS3.1 中的新功能以及在相机视图之上覆盖视图的更新功能。这效果很好。

但是,我目前正在开发一个项目,我希望能够在现有视图中显示 UIImagePickerController 的相机视图。本质上,这与我目前所做的完全相反。

一个例子是带有导航组件的视图控制器(想想带有渐变的顶部和底部水平栏),点击其中一个栏上的按钮后,内容区域将显示相机视图。快门动画应该向上,并且顶部和底部导航栏将始终保持在顶部。

我已经成功地将 UIImagePickerController 添加到窗口视图中,并以模态方式呈现它,但没有将其添加为子视图。

前任:

[window addSubview:camera.view];
[self presentModalViewController:camera animated:YES];

I've been working pretty extensively the last couple months with UIImagePickerController, particularly with the new capabilities in OS3.1 and newer to overlay views on-top of the camera view. This has worked just fine.

However, I am currently working on a project where I'd like to be able to display the camera view of the UIImagePickerController within an existing view. Essentially, the exact opposite of what I've currently been doing.

An example would be a View Controller with navigation components (Think top and bottom horizontal bars with gradients), and upon tapping a button on one of these bars, then content area displays the camera view. The shutter animation would should up, and the top and bottom navigation bars would remain always on-top.

I've had success adding the UIImagePickerController to the window view, as well as presenting it modally, but haven't had any luck adding it as a subView.

ex:

[window addSubview:camera.view];
[self presentModalViewController:camera animated:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

韵柒 2024-08-19 03:16:48

您所需要做的就是调用 viewWillAppear 和 viewDidAppear。

下面是一个示例,其中 _pickerController 是 UIImagePickerController 的实例:

[self.view addSubview:_pickerController.view];
[_pickerController viewWillAppear:YES];
[_pickerController viewDidAppear:YES];

All you need to do is call viewWillAppear and viewDidAppear.

Here is an example where _pickerController is an instance of UIImagePickerController:

[self.view addSubview:_pickerController.view];
[_pickerController viewWillAppear:YES];
[_pickerController viewDidAppear:YES];
荒人说梦 2024-08-19 03:16:48

将其视图添加到视图后,在图像选择器控制器上调用 viewWillAppear:YES 。跳过模态视图控制器业务。

Call viewWillAppear:YES on the image picker controller after adding its view to your view. Skip the modal view controller business.

满天都是小星星 2024-08-19 03:16:48

我不认为 API 提供对 UIImagePickerController 实际视图的直接访问。该类实际上是 UINavigationController 的子类,因此我认为它本身没有实际的视图,而是管理其子控制器及其视图的调用。

当您以模态方式调用 UIImagePickerController 时,它不会将其控制的视图作为子视图添加到窗口(或任何其他视图)。这就是模态视图的含义。它将视图呈现到视图层次结构的“一侧”。

即使你可以将其整合在一起,我认为 Apple 也会拒绝它,因为它不是 API 的一部分并且违反了 HIG。

I don't think the API provides direct access to the actual view of the UIImagePickerController. The class is actually a subclass of UINavigationController so I don't think it has an actual view itself but rather manages the calling of its subcontrollers and their views.

When you call the UIImagePickerController modally, its doesn't add the views it controls as subviews to the window (or any other view). That is what a modal view means. It presents the view off to the "side" of the view hierarchy.

Even if you could hack this together, I think Apple would reject it as not being part of the API and for violating the HIG.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文