Setting UIImagePickerController Frame Size

Can I change the display frame size of a UIImagePickerController? I want to display the camera view, but not in full screen, but I will say in the bounding box 100x100.

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 this anywhere ... doesn't anyone use it?

+6
source share
3 answers

I experimented with the code from my last post and commented on the final scale scale ((the one that makes it full size), and I ended up with a beautiful miniature imagePicker camera floating in the middle of my screen, so it definitely works! The exact code I used, including transition with increase / gradual transition, -

 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 am sure that you could adjust it more, change the size and location of the camera.

+12
source

If you want to display the overlay on top of the UIImagePickerController, for example, in my case, and at the same time adjust the "live camera" controller (view) between some components of the user interface on your overlay (for example, the top panel and the bottom panel), use the following code. This is based on SomaMan's answer above (THANKS), with the main difference being displaying the UIImagePickerController as a sub-view of the current controller, and not as a subspecies 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 executing CameraViewTransform, do not forget to apply the same transformation on the resulting photo that the collector will capture for you if you want the user to be in the same image that they see in your converted form: P

+3
source

I sometimes added the ImagePicker view directly, although I never experimented with changing its final size, it โ€œapproachesโ€ the screen, suggesting that it could be displayed in different sizes (the code was shot directly from one of my projects, so probably not everything is 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 find out if you have any results.

+1
source

Source: https://habr.com/ru/post/913259/


All Articles