UIImagePickerController 不填满屏幕
我正在向 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% 效果很好。当我在屏幕底部添加自定义工具栏时,窗口中不再有可见的黑条。
I'm adding a custom overlay to the UIImagePickerController and there is a persistant black bar at the bottom of the view. Here is my code to instantiate the controller.
- (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;
}
The returned controller is displayed modally and works just fine (i.e. displays full screen) when I'm not hiding the camera controls.
Thanks to Ole's suggestion I got it working with this code:
// Resize the camera preview
_imagePicker.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.03);
A 3% increase in height worked just fine. When I add my custom toolbar at the bottom of the screen there is no longer a visible black bar across the window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
尝试使用此代码:
Try use this code:
按固定值缩放并不是一个好主意...因为我确信使用此处接受的答案的任何人都可能在 iPhone 5 推出时发现了这一点。
这是一个根据屏幕分辨率动态缩放以消除字母框的代码片段。
Scaling by a fixed value isn't a good idea... as I'm sure anyone who used the accepted answer here probably found out when the iPhone 5 came out.
Here's a code snippet to scale dynamically based on the screen resolution to eliminate the letter boxing.
相机的长宽比为4:3,屏幕的长宽比为3:2。因此,除非您愿意将相机图片裁剪为 3:2,否则根本无法让相机图片填满屏幕。为此,请应用适当的比例变换。
The camera's aspect ratio is 4:3 and the screen's aspect ratio is 3:2. So there is simply no way for the camera picture to fill the screen unless you're willing to crop is to 3:2. To do that, apply an appropriate scale transform.
嘿,我看到有些人在计算 iPhone 5 的比例后仍然出现底部的黑条。我遇到这个问题有一段时间了,但后来我发现你必须翻译视图,使其位于屏幕中间然后应用比例。这是我执行这两件事的代码,它对我有用!
Hey I saw some people were still getting the black bar at the bottom after calculating the scale for the iPhone 5. I had this problem for a while but then I figured out you have to translate the view so it is in the middle of the screen and then apply the scale. Here is my code for doing those two things and it works for me!
根据我在 iOS 7、iPhone 5S 上的经验,要在全屏预览中看到图片的中心,您必须连接转换,而不是按顺序进行转换:
From my experience on iOS 7, iphone 5S, to see the center of the picture into the full-screen preview you have to concatenate the transformations, not make them sequentially:
用这个来改变它:
Transform it with this:
这是 Swift 的答案。
And here the answer in Swift.
这在 iOS 10 上对我有用:
This worked for me on iOS 10:
我用这个方法来计算比例。
I used this method to calculate the scale.
我的问题解决了:)
my issue solved :)
这些解决方案对我来说并不完全有效。在 iOS 13.x 下运行并使用 iPhone 6+ 和 iPhone 11 Pro 时,底部仍然有黑条。我能够通过计算中心偏移并将其应用于比例计算来解决这两个问题,而无需使用幻数。这在 6+ 和 11 Pro 上再次有效。
These solutions did not work in total for me. There was still a black bar at the bottom running under iOS 13.x and using an iPhone 6+ and an iPhone 11 Pro. I was able to resolve for both, without using magic numbers, by calculating the offset to center and applying that to the scale calculation. This worked again with both a 6+ and an 11 Pro.
Swift 5
100% 工作
简单的解决方案
如果您想在某些自定义 UIView 中显示相机,请使用该代码,相机将在全屏中显示,
上部用于代表,底部用于功能,
如果您希望从主屏幕显示,则需要更改比率 (4.0/3.0)
< a href="https://i.sstatic.net/nwLIB.jpg" rel="nofollow noreferrer">
Swift 5
100% working
Easy Solution
If you want show camera in some custom UIView so use that code and camera will be show in full screen
upper section is for delegate and bottom is function
if you want it from main screen then you need to change the ratio (4.0/3.0)
这就是 Swift 4 对我有用的东西
This is what works for me with Swift 4
以下工作对我来说可以消除信箱并捕获与精确设备高度匹配的全屏图像。该代码是用 Swift 5 编写的。
Following works for me to eliminate Letter boxing and capture full screen images matching exact device height. The code is written in Swift 5.