Displaying UIImagePickerController within another UIView

杀马特。学长 韩版系。学妹 提交于 2020-01-20 08:17:25

问题


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

回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/1759194/displaying-uiimagepickercontroller-within-another-uiview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!