configurationUIImagePickerController的帧大小

是否有可能更改UIImagePickerController的可显示的框架大小? 我想要显示相机视图,但不是在整个屏幕上,但在100×100的边界框中说。

这是我的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]; } 

我找不到在任何地方这样做的方法…没有人使用它?

我用我上一篇文章的代码进行了实验,并将最终的缩放转换((使其成为全尺寸的转换)注释掉了,最后我在屏幕中间浮动了一个可爱的微型相机imagePicker,所以它确实能够工作!我使用的确切代码,包括缩放/淡入转换,是 –

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

我相信你可以定制更多,改变相机视图的大小和位置。

如果你想在UIImagePickerController的顶部显示一个叠加层(例如在我的例子中),同时在你的叠加层上的一些UI组件之间(如顶部柱和一个底部栏),使用下面的代码。 这是基于SomaMan上面的回答(THANKS),主要区别在于将UIImagePickerController视图显示为当前控制器的子视图,而不是主应用程序窗口的子视图。 把这个代码放在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]; 

提示:在进行cameraViewTransform时,如果您希望用户最终看到通过转换后的选取器视图看到的相同图像,请确保在所得照片上应用相同的变换:拾取器为您捕获的图像:P

我有时直接添加了ImagePicker的视图,虽然我从来没有尝试过改变它的最终大小,它会“缩放”到屏幕上,这意味着它可能以不同的大小显示(代码直接从我的项目,所以可能不是全部相关) –

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

有兴趣看看你是否得到任何结果。