如果你想在 UIImagePickerController 的顶部显示一个覆盖,比如在我的例子中,同时在你的覆盖上的一些 UI 组件(比如顶部栏和底栏),请使用以下代码。这是基于上面 SomaMan 的回答(谢谢),主要区别是将 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