我正在为iPhone 5制造全屏摄像头,并具有以下代码来缩放4:3摄像头以填充整个屏幕,即2:3的比例。左侧和右侧从屏幕渗出。
我必须将cameraView向下移动71点以使其与屏幕居中。否则,底部会有一个黑条。我不太确定为什么。因为我不知道为什么会这样,所以我不知道如何动态编码调整以适应iPhone 6和6 Plus。
任何帮助表示赞赏。
// get the screen size
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
// establish the height to width ratio of the camera
float heightRatio = 4.0f / 3.0f;
// calculate the height of the camera based on the screen width
float cameraHeight = screenSize.width * heightRatio;
// calculate the ratio that the camera height needs to be scaled by
float ratio = screenSize.height / cameraHeight;
//This slots the preview exactly in the middle of the screen by moving it down 71 points (for iphone 5)
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0);
self.camera.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, ratio, ratio);
self.camera.cameraViewTransform = scale;
这终于在我的脑海中震撼了。由于我们知道摄像头的长度将始终与屏幕宽度相同:
//以4:3的比例获取相机高度
int cameraViewHeight = SCREEN_WIDTH * 1.333;
int adjustedYPosition = (SCREEN_HEIGHT - cameraViewHeight) / 2;
CGAffineTransform translate = CGAffineTransformMakeTranslation(0, adjustedYPosition);
self.imagePicker.cameraViewTransform = translate;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句