如何添加 UIImagePickerController 作为子视图而不是模态视图

发布于 2024-09-18 00:14:27 字数 586 浏览 5 评论 0原文

我的一个视图上有一个段控制器,现在在段控制器的第 0 个索引上,我想通过添加为子视图而不是通过 ModalViewController 添加 UIImagePickerController (用于向用户显示相机视图)。现在视图已加载,但它不显示任何相机视图。我可以通过 PresentModalViewController 并传递其对象来显示相机视图。

这是代码——

if(segmentedControl.selectedSegmentIndex==0)

{

UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];

cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;

cameraView.showsCameraControls = NO;

//[self presentModalViewController:cameraView animated:YES]; //Working

[self.view addSubview:cameraView.view]; // Not Working

}

I have a segment controller on one of my views and now on the 0th index of segment controller I want to add UIImagePickerController (for showing camera view to user) by adding as sub view and not by ModalViewController. Right now the view gets loaded but It does not show any camera view. I am able to show the camera view by presentModalViewController and passing its object.

Here's the code--

if(segmentedControl.selectedSegmentIndex==0)

{

UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];

cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;

cameraView.showsCameraControls = NO;

//[self presentModalViewController:cameraView animated:YES]; //Working

[self.view addSubview:cameraView.view]; // Not Working

}

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

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

发布评论

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

评论(2

策马西风 2024-09-25 00:14:27
[self.view addSubview:picker.view];
[picker viewWillAppear:YES]; // trickery to make it show
[picker viewDidAppear:YES];

作为副作用,您会在顶部看到一个白条,因为 UIImagePickerController 不打算与它一起使用。

[self.view addSubview:picker.view];
[picker viewWillAppear:YES]; // trickery to make it show
[picker viewDidAppear:YES];

You get a white bar at the top as side effect since UIImagePickerController is not intended to be used with it.

无所的.畏惧 2024-09-25 00:14:27

您应该避免这样做,不建议这样做,并且可能会导致不必要的副作用。

如文档中所述(https://developer.apple.com/library /ios/documentation/UIKit/Reference/UIImagePickerController_Class)您不能将其添加为子视图,您应该将其呈现为新控制器

这里是文档的一部分:

在 iPhone 或 iPod touch 上,通过调用以模式方式(全屏)执行此操作
presentViewController:animated:completion: 当前的方法
活动视图控制器,传递您配置的图像选择器
控制器作为新的视图控制器。

希望这有帮助!

You should avoid doing this, it is not recommended and could lead to unwanted side effects.

As stated on the documentation (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class) you cannot add it as a subview, you should present it as a new controller

Here a piece of the doc:

On iPhone or iPod touch, do this modally (full-screen) by calling the
presentViewController:animated:completion: method of the currently
active view controller, passing your configured image picker
controller as the new view controller.

Hope this helpes!

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