首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIImagePickerController不会填充屏幕

UIImagePickerController不会填充屏幕
EN

Stack Overflow用户
提问于 2010-04-20 18:46:27
回答 13查看 31.9K关注 0票数 61

我正在向UIImagePickerController添加一个自定义覆盖,在视图底部有一个持续存在的黑条。下面是我实例化控制器的代码。

代码语言:javascript
运行
复制
- (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的建议,我用下面的代码让它工作起来:

代码语言:javascript
运行
复制
// Resize the camera preview
        _imagePicker.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.03);

身高增加3%就可以了。当我在屏幕底部添加自定义工具栏时,窗口上不再有可见的黑条。

EN

回答 13

Stack Overflow用户

回答已采纳

发布于 2010-04-20 21:15:36

相机的宽高比是4:3,屏幕的宽高比是3:2。因此,除非你愿意裁剪到3:2,否则相机的图片根本无法填满屏幕。要做到这一点,请应用适当的比例变换。

票数 38
EN

Stack Overflow用户

发布于 2013-04-04 14:25:01

按固定值缩放不是一个好主意……我敢肯定,任何使用这里公认答案的人都可能在iPhone 5出来的时候发现了这一点。

下面是一段代码片段,可以根据屏幕分辨率动态缩放,以消除字母框。

代码语言:javascript
运行
复制
// 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);
票数 53
EN

Stack Overflow用户

发布于 2013-11-27 05:28:18

嘿,我看到一些人在计算了iPhone 5的比例后,仍然看到底部的黑条。我遇到这个问题有一段时间了,但后来我发现你必须转换视图,使其位于屏幕中间,然后应用比例。下面是我用来做这两件事的代码,它对我很有效!

代码语言:javascript
运行
复制
    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);
票数 22
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2674375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档