更改UIImagePicker的宽高比

时间:2014-03-23 15:29:28

标签: ios iphone objective-c cocoa-touch

所以我试着在我的iOS应用程序中制作自定义相机。

我想让相机全屏像snapchats一样。

但我无法找到任何可以帮助我将纵横比从4:3(默认)更改为16:9(iPhone 5& 5s,4"屏幕)的地方。

有人能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:3)

这里有一点无耻的自我推销,但我有一个相机项目,可以做你想做的一切,而且你可以为你的项目进一步定制。 GitHub

它可以为您完成所有切割/尺寸/宽高比,同时仍然在所有设备上全屏显示。

否则,如果您不喜欢github / cocoacontrols /其他地方还有很多其他选项。您也可以通过查看AVFoundation

来制作自己的

答案 1 :(得分:0)

您需要更改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);