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
If you want to display an overlay on top of the UIImagePickerController, such as in my case, while at the same time fitting the controller's "live camera feed" (the view) in between some UI components on your overlay (such as a top bar and a bottom bar), use the following code. This is based on SomaMan's answer above (THANKS), with the main difference of displaying UIImagePickerController's view as a subview of the current controller instead of as a subview of the main application window. Put this code in viewDidLoad():
// Overlay view with custom camera controls and a top bar and a bottom bar
self.overlay = [[CameraOverlayView alloc] initWithFrame:self.view.bounds];
[self setOverlayViewModel];
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.imagePicker.showsCameraControls = NO;
self.imagePicker.navigationBarHidden = YES;
self.imagePicker.toolbarHidden = YES;
self.imagePicker.delegate = self;
UIView *imagePickerView = self.imagePicker.view;
if ([[UIScreen mainScreen] bounds].size.height == 568.0f) {
// iPhone 5, 16:9 ratio, need to "zoom in" in order to fill the screen since there is extra space between top and bottom bars on a taller screen
self.imagePicker.cameraViewTransform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, 1.5, 1.5); // change 1.5 to suit your needs
}
CGRect cameraViewFrame = CGRectMake(0, self.overlay.topBarHeight,
self.view.bounds.size.width,
self.view.bounds.size.height - self.overlay.topBarHeight - self.overlay.bottomBarHeight);
imagePickerView.frame = cameraViewFrame;
// keep this order so that the overlay view is on top of the "live camera feed" view
[self.view addSubview:imagePickerView];
[self.view addSubview:self.overlay];
TIP: When doing cameraViewTransform, make sure to apply the same transform on the resulting photo that the picker captures for you if you want the user to end up with the same image that they see through your transformed picker's view :P
I've sometimes added the ImagePicker's view directly, though I've never experimented with changing its final size, it does "zoom" into the screen, suggesting that it might be possible to show it at different sizes (code lifted directly from one of my projects, so probably not all relevant) -
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.transform = CGAffineTransformMakeScale(1.0, 1.0);
controllerView.alpha = 1.0;
}
completion:nil
];
[imagePickerController release];
Be interested to see if you get any results with this.
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.