gpt4 book ai didi

ios - 为 iOS 8 动态设置 cameraViewTransform

转载 作者:可可西里 更新时间:2023-11-01 04:41:10 25 4
gpt4 key购买 nike

我正在开发一个相机应用程序,我应该在里面展示一个相机 enter image description here

我正在使用 camView.cameraViewTransform = CGAffineTransformMakeScale(1.0, 1.0) ; 但是对于不同的设备会得到不同的结果,并且在标签栏和相机之间有一个黑条。如果我更改 scaling 的值,相机会过度放大。在此问题上的任何帮助将不胜感激。

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self prepareCamera];
}

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:NO];
[self launchCamera];
}

- (void)prepareCamera{
camView = [[UIImagePickerController alloc] init];
camView.delegate = self;
camView.sourceType = UIImagePickerControllerSourceTypeCamera;
camView.showsCameraControls = NO;
[self resizeCameraView];
}


- (void)resizeCameraView{
CGSize screenSize = self.view.bounds.size;
// set the aspect 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 scale = screenSize.height / cameraHeight;
// move the controller to the center of the screen
camView.cameraViewTransform = CGAffineTransformMakeTranslation(0, (screenSize.height - cameraHeight) / 2.0);
// concatenate the scale transform
camView.cameraViewTransform = CGAffineTransformScale(camView.cameraViewTransform, scale, scale);
}

- (void)launchCamera{
[camSubView addSubview:camView.view];
[camView viewWillAppear:YES];
[camView viewDidAppear:YES];
}

最佳答案

Apple 不正式支持您要实现的目标。来自UIImagePickerController Class Reference :

To use an image picker controller containing its default controls, perform these steps:

...

  1. Present the user interface. On iPhone or iPod touch, do this modally (full-screen) by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.

    On iPad, if you specify a source type of UIImagePickerControllerSourceTypeCamera, you can present the image picker modally (full-screen) or by using a popover. However, Apple recommends that you present the camera interface only full-screen.

您可以做的是以模态方式(全屏)呈现 UIImagePickerController 并使用 cameraOverlayView 添加自定义控件。属性(property)。

解决方案

要实现您想要的效果,您必须使用 AVFoundation 而不是 UIImagePickerController。 AV Foundation 库提供了一种更强大的拍照方式,让您可以将相机 View 放入您自己的应用程序中。可以找个好的教程here ,或更新的 here

关于ios - 为 iOS 8 动态设置 cameraViewTransform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32962068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com