在 iPhone X 上缩放全屏相机
Scale for fullscreen camera on iPhone X
我已经使用 UIImagePickerController
在我的应用程序中实现了自定义相机。我之前通过应用 this transformation:
使相机全屏显示
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
//For iphone 5+
//Camera is 426 * 320. Screen height is 568. Multiply by 1.333 in 5 inch to fill vertical
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
ipc.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
ipc.cameraViewTransform = scale;
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = NO;
[self presentViewController:ipc animated:YES completion:nil];
}
但是,iPhoneX的摄像头并没有填满屏幕。它与屏幕顶部齐平,但底部有一个黑条。
我认为问题是 1.3 是垂直填充屏幕的错误比例。我希望摄像头填满 phone 的整个屏幕 iPhone X.
如果您可以计算它,那么硬编码该比率在这里没有多大意义。
您通过将屏幕高度 (568) 除以相机视图的高度 (426) 计算出 1.3333。该逻辑在 X 上应该是相同的,但您需要提供正确的参数,而不是假设所有手机共享相同的屏幕尺寸。
另请注意,如果您选择按比例缩放,变换此图像可能会导致部分图像被截掉。
我已经使用 UIImagePickerController
在我的应用程序中实现了自定义相机。我之前通过应用 this transformation:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
//For iphone 5+
//Camera is 426 * 320. Screen height is 568. Multiply by 1.333 in 5 inch to fill vertical
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
ipc.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
ipc.cameraViewTransform = scale;
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = NO;
[self presentViewController:ipc animated:YES completion:nil];
}
但是,iPhoneX的摄像头并没有填满屏幕。它与屏幕顶部齐平,但底部有一个黑条。
我认为问题是 1.3 是垂直填充屏幕的错误比例。我希望摄像头填满 phone 的整个屏幕 iPhone X.
如果您可以计算它,那么硬编码该比率在这里没有多大意义。
您通过将屏幕高度 (568) 除以相机视图的高度 (426) 计算出 1.3333。该逻辑在 X 上应该是相同的,但您需要提供正确的参数,而不是假设所有手机共享相同的屏幕尺寸。
另请注意,如果您选择按比例缩放,变换此图像可能会导致部分图像被截掉。