在iPhone X上进行全屏相机缩放(Scale for fullscreen camera on iPhone X)

编程入门 行业动态 更新时间:2024-10-11 19:14:53
在iPhone X上进行全屏相机缩放(Scale for fullscreen camera on iPhone X)

我已经在我的应用程序中使用UIImagePickerController实现了一个自定义相机。 我以前通过应用这个转换使相机全屏:

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]; }

但是,相机没有填满iPhone X的屏幕。它与屏幕顶部齐平,但底部有一个黑色条。

我认为问题是1.3是垂直填充屏幕的错误比例。 我希望相机能够为iPhone X填满整个手机屏幕。

I have implemented a custom camera in my app using UIImagePickerController. I previously made the camera full screen by applying 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]; }

However, the camera does not fill the screen of the iPhone X. Its flush with the top of the screen, but there is a black bar at the bottom.

I assume the issue is that 1.3 is the wrong scale to vertically fill the screen. I would like the camera to fill the entire screen of the phone for the iPhone X.

最满意答案

如果你可以计算它,硬编码这个比例在这里没有多大意义。

您通过将屏幕高度(568)除以相机视图的高度(426)来计算1.3333。 该逻辑应该在X上工作相同,但您需要提供正确的参数,而不是假设所有手机共享相同的屏幕尺寸。

另请注意,如果您选择按比例缩放,转换此图像可能会导致部分图像被切断。

Hard-coding that ratio doesn't make much sense here if you can calculate it instead.

You calculated 1.3333 by dividing screen height (568) by the height of the camera view (426). That logic should work the same on the X but you need to provide the correct parameters instead of assuming all phones share the same screen dimensions.

Also keep in mind that transforming this image may result in parts of it being cut off if you chose to scale proportionately.

更多推荐

本文发布于:2023-08-04 03:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408961.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缩放   全屏   相机   iPhone   fullscreen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!