Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动态居中已放大至全屏的UIImagepicker取景器_Ios_Objective C_Iphone_Ios8_Uiimagepickercontroller - Fatal编程技术网

Ios 动态居中已放大至全屏的UIImagepicker取景器

Ios 动态居中已放大至全屏的UIImagepicker取景器,ios,objective-c,iphone,ios8,uiimagepickercontroller,Ios,Objective C,Iphone,Ios8,Uiimagepickercontroller,我正在为iPhone5制作一个全屏摄像头,并使用以下代码缩放4:3的摄像头以填充整个屏幕,即2:3的比例。左右两侧从屏幕上放气 我必须将摄像机向下移动71点,使其与屏幕居中。否则,底部会有一个黑条。我不太清楚为什么。因为我不知道为什么会发生这种情况,我不知道如何动态编码调整以适应iPhone 6和6 Plus 感谢您的帮助 // get the screen size CGSize screenSize = [[UIScreen mainScreen] bounds].size; // est

我正在为iPhone5制作一个全屏摄像头,并使用以下代码缩放4:3的摄像头以填充整个屏幕,即2:3的比例。左右两侧从屏幕上放气

我必须将摄像机向下移动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;