开发者

Resize UIImagePickerController video capture interface

开发者 https://www.devze.com 2023-04-03 12:07 出处:网络
I am using splitviewcontroller for my ipad application in which I need to capture video in the detailViewController in a dimension of 530 px width and 360 px height. I tried using UIImagePickerControl

I am using splitviewcontroller for my ipad application in which I need to capture video in the detailViewController in a dimension of 530 px width and 360 px height. I tried using UIImagePickerController for capturing video but i am unable to change开发者_运维技巧 the size of the video capture interface. I cannot afford a full screen video capture in the app. Is there a way to resize the video capture interface of UIImagePickerController. Thanks a lot for your answers. Sorry for not adding up an screenshot here. My reputation count doesn't permit it.


You won't be able to do so using UIImagePickerController as far as I know. But you can do it easily using AVCamCaptureManager and AVCamRecorder classes. Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it calls the classes and methods which are responsible for opening the iPhone's camera and record video or capture audio. It calls the same classes which are called by UIImagePickerController.

You'll find a small UIView object in that demo code which displays the camera's feed. You can resize that view as per the size you want and the camera's input will be displayed in that much area. It worked for me when I wanted to resize the camera's input feed and capture photos. I hope it works for you as well.


I just found a possible way to resize UIImagPickerController video capture interface on iPad. The basic idea is to use UIPopoerController's dimension to resize the UIImagPickerController's view and then add it to your custom view.

The detailed code and description are listed below:

//In the following code, videoRecorder is an UIImagPickerController  

//1. Create a container view controller and load UIImagPickerController's view
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(320, 240);
[containerController.view addSubview:videoRecorder.view];

//2. Add the container view controller in a UIPopoerController and present the popover outside the visible area on the screen (you can't see it but the popover was presented)
popoverView = [[UIPopoverController alloc] initWithContentViewController:containerController];                    
popoverView.passthroughViews = [NSArray arrayWithObjects:self.view, nil];
[popoverView setPopoverContentSize:CGSizeMake(320, 240)];
[popoverView presentPopoverFromRect:CGRectMake(0, -1024, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];   

//3. Reset the frame of UIImagPickerController's view to meet the frame of its container - this is important to resize the UIImagPickerController's view and must do this step after the popover was presented.                                    
[videoRecorder.view setFrame:containerController.view.frame];

//4. Add the container view controller's view to your custom view - in this example, it is 'camView' with the size 320 x 240
[camView addSubview:containerController.view];   

Note : when you finish video capture or cancel it, you need to dismiss the popover and remove the container's view from your custom view.

[popoverView dismissPopoverAnimated:YES];
[[camView.subviews lastObject] removeFromSuperview];
0

精彩评论

暂无评论...
验证码 换一张
取 消