如何添加 UIImagePickerController 作为子视图而不是模态视图
我的一个视图上有一个段控制器,现在在段控制器的第 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为副作用,您会在顶部看到一个白条,因为 UIImagePickerController 不打算与它一起使用。
You get a white bar at the top as side effect since UIImagePickerController is not intended to be used with it.
您应该避免这样做,不建议这样做,并且可能会导致不必要的副作用。
如文档中所述(https://developer.apple.com/library /ios/documentation/UIKit/Reference/UIImagePickerController_Class)您不能将其添加为子视图,您应该将其呈现为新控制器
这里是文档的一部分:
希望这有帮助!
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:
Hope this helpes!