简体   繁体   English

更改UIImagePicker的宽高比

[英]change UIImagePicker aspect ratio

So im trying to make a custom camera within my iOS app. 所以我试图在我的iOS应用程序中制作自定义相机。

I want to make the camera full screen like snapchats. 我想让相机全屏像snapchats。

But i cant find anywhere that will help me change the aspect ratio from 4:3 (default) to 16:9 (iPhone 5 & 5s, 4" screens). 但我无法找到任何可以帮助我将宽高比从4:3(默认)更改为16:9(iPhone 5和5s,4“屏幕)的地方。

Can anyone point me in the right direction? 谁能指出我正确的方向?

A little shameless self promotion here, but I have a camera project that does everything you'd like to do, plus you could customize it further for your project. 这里有一点无耻的自我推销,但我有一个相机项目,可以做你想做的一切,而且你可以为你的项目进一步定制它。 GitHub GitHub上

It does all the cutting / sizing / aspect ratios for you, while still being fullscreen on all devices. 它可以为您完成所有切割/尺寸/宽高比,同时仍然可以在所有设备上全屏显示。

Otherwise, There's many other options on github / cocoacontrols / elsewhere if you don't like it. 否则,如果您不喜欢它,github / cocoacontrols /其他地方还有很多其他选项。 You could also make your own by checking out AVFoundation 你也可以通过检查AVFoundation制作自己的

You need to change the UIImagePickerController's cameraViewTransform: 您需要更改UIImagePickerController的cameraViewTransform:

CGSize screenBounds = [UIScreen mainScreen].bounds.size;

CGFloat cameraAspectRatio = 4.0f/3.0f;

CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
CGFloat scale = screenBounds.height / camViewHeight;

pickerController.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenBounds.height - camViewHeight) / 2.0);
pickerController.cameraViewTransform = CGAffineTransformScale(pickerController.cameraViewTransform, scale, scale);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM