Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuring frame size of UIImagePickerController

Is it possible to change the displayable frame size of UIImagePickerController? I want to display camera view but not on the entire screen, but say in a 100x100 bounding box.

Here is my viewDidAppear:

- (void) viewDidAppear:(BOOL)animated {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

[self presentModalViewController:picker animated:YES];  

[super viewDidAppear:YES];
 }

I could not find a way to do that anywhere...doesnt anyone using it?

like image 636
TommyG Avatar asked Apr 15 '12 17:04

TommyG


1 Answers

I experimented with the code from my last post, and commented out the final scale transform ((the one which makes it full size) and I ended up with a lovely miniature camera imagePicker floating in the middle of my screen, so it definitely does work! The exact code I used, including the zoom/fade-in transition, is -

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

imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

UIView *controllerView = imagePickerController.view;

controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);

[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];

[UIView animateWithDuration:0.3
                  delay:0.0
                options:UIViewAnimationOptionCurveLinear
             animations:^{
                 controllerView.alpha = 1.0;
             }
             completion:nil
 ];

[imagePickerController release];

I'm sure you could customise it more, change the size & location of the camera view.

like image 188
SomaMan Avatar answered Oct 23 '22 05:10

SomaMan