ios - iphone 5 - 在屏幕上居中 UIImagePickerController

标签 ios objective-c nslayoutconstraint camera-overlay ios-camera

我使用以下代码为相机创建了一个自定义叠加层:

- (void) showCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    self.picker.showsCameraControls = NO;
    self.picker.navigationBarHidden = YES;
    self.picker.toolbarHidden = YES;

    self.overlay = [[CameraOverlayViewController alloc] init];
    self.overlay.pickerReference = self.picker;
    self.picker.cameraOverlayView = self.overlay.view;
    self.picker.delegate = self.overlay;

    [self presentViewController:self.picker animated:NO completion:nil];
}

它在 iphone 4 上工作正常(因为摄像头覆盖了整个屏幕),但在 iphone 5 上摄像头位于屏幕顶部,底部留下黑色方 block 。 因为我不能改变相机尺寸,至少我想把它放在屏幕中间, 然后添加 UIViews 作为边距(非常类似于苹果的 Camera Roll 应用程序,相机不在屏幕顶部,并且在它的上方和下方都有控件)。

有人可以告诉我在这种情况下如何控制相机框架吗? 另外,由于边距只是为了更好的可视化,我可能不想在 iphone 4 或 ipad 屏幕上显示它们。

提前致谢!

最佳答案

使用 cameraViewTransform 属性更改相机的 y 位置。例如:

if(IS_IPHONE_5){
    CGAffineTransform tr =  self.imagePickerController.cameraViewTransform;
    tr.ty = 70;
    self.imagePickerController.cameraViewTransform= tr;
}

IS_IPHONE_5 是:

#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

关于ios - iphone 5 - 在屏幕上居中 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20259399/

相关文章:

ios - Apple Watch 模拟器无法启动

objective-c - sqlite fts 不适用于临时版本的应用程序,但仅适用于从 xcode 启动的版本

ios - 使用编程约束时如何将 CAGradientLayer 添加到 UIView

ios - 如何解决: Unable to simultaneously satisfy constraints

ios - 如何以编程方式将顶部约束更改为布局中的另一个项目

ios - 如何从模态视图重新加载背景 UITableView

html - 修复了当我在 iOS Safari 9+ 中快速滚动到底部时元素不可点击的问题

objective-c - 为什么Xcode中突然出现大量编译器错误?

ios - RxSwift Realm 在 RunLoop 中观察 Array

iphone - UIApplicationDidFinishLaunchingNotification的使用