我正在向UIImagePickerController添加一个自定义覆盖,在视图底部有一个持续存在的黑条。下面是我实例化控制器的代码。
- (UIImagePickerController *)imagePicker {
if (_imagePicker) {
return _imagePicker;
}
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.showsCameraControls = NO;
_imagePicker.wantsFullScreenLayout = YES;
_imagePicker.navigationBarHidden = YES;
_imagePicker.toolbarHidden = YES;
} else {
_imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
return _imagePicker;
}
多亏了Ole的建议,我用下面的代码让它工作起来:
// Resize the camera preview
_imagePicker.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.03);
身高增加3%就可以了。当我在屏幕底部添加自定义工具栏时,窗口上不再有可见的黑条。
发布于 2010-04-20 21:15:36
相机的宽高比是4:3,屏幕的宽高比是3:2。因此,除非你愿意裁剪到3:2,否则相机的图片根本无法填满屏幕。要做到这一点,请应用适当的比例变换。
发布于 2013-04-04 14:25:01
按固定值缩放不是一个好主意……我敢肯定,任何使用这里公认答案的人都可能在iPhone 5出来的时候发现了这一点。
下面是一段代码片段,可以根据屏幕分辨率动态缩放,以消除字母框。
// Device's screen size (ignoring rotation intentionally):
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
// iOS is going to calculate a size which constrains the 4:3 aspect ratio
// to the screen size. We're basically mimicking that here to determine
// what size the system will likely display the image at on screen.
// NOTE: screenSize.width may seem odd in this calculation - but, remember,
// the devices only take 4:3 images when they are oriented *sideways*.
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf((screenSize.height / imageWidth) * 10.0) / 10.0;
self.ipc.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
发布于 2013-11-27 05:28:18
嘿,我看到一些人在计算了iPhone 5的比例后,仍然看到底部的黑条。我遇到这个问题有一段时间了,但后来我发现你必须转换视图,使其位于屏幕中间,然后应用比例。下面是我用来做这两件事的代码,它对我很有效!
CGSize screenBounds = [UIScreen mainScreen].bounds.size;
CGFloat cameraAspectRatio = 4.0f/3.0f;
CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;
m_imagePickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
m_imagePickerController.cameraViewTransform = CGAffineTransformScale(m_imagePickerController.cameraViewTransform, scale, scale);
https://stackoverflow.com/questions/2674375
复制相似问题