gpt4 book ai didi

ios - UIImagePicker 仅适用于 iPhone 6 plus 上的前置摄像头

转载 作者:行者123 更新时间:2023-11-29 02:21:49 24 4
gpt4 key购买 nike

使用以下代码:

- (void) viewDidAppear:(BOOL)animated {

[super viewDidAppear:animated];

if (!self.alreadyAppeared) {

[self performSelector:@selector(showCamera) withObject:nil afterDelay:0.3];
}

}

-(void)showCamera
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.delegate = self;

[self presentViewController: picker animated:YES completion:NULL];
}

我的应用程序运行完美。但是如果我改变

picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;

我失去了形象。以下代码是我如何捕获图像并在我的应用程序中设置 ImageView 。我使用导航 Controller 返回应用程序:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
self.cf.imageView.image = chosenImage;

NSLog(@"%@",chosenImage);
[picker dismissViewControllerAnimated:YES completion:NULL];

// pop back to previous controller
NSArray *myControllers = self.nc.viewControllers;
int previous = (int)myControllers.count - 2;
UIViewController *previousController = [myControllers objectAtIndex:previous];

[self.nc popToViewController:previousController animated:YES];

}

同样,这在我的 iPad 上运行得很好,并且使用前置摄像头也运行得很好。即使使用后置摄像头,所选图像(我记录的)也显示正确。有人知道为什么后置摄像头设置会产生这样的效果吗?

另一件事:我收到一条非常令人恼火的消息,其中有大约 1,000 种不同的解释,但没有一个可以消除该消息:

对尚未渲染的 View 进行快照会产生空快照。确保您的 View 在快照之前或屏幕更新后的快照之前至少已渲染一次。

最佳答案

使用 iPhone 6 和 6 plus 时,必须防止每次离开相机控件(选择器)时重新加载 View 。我的应用程序使用一个 View Controller 来创建一个动态 View ,它是一种形式。该表单上的每个字段都是从 Web 服务中提取的,并成为表单的 subview 。这包括相机字段,我使用 viewcontroller 和 xib 来构建字段。表单 View 通过 drawRect 方法构建整个表单。每次导航离开时,相机字段都会尝试调用该方法。我阻止它重新加载,这似乎解决了问题。

更标准的应用程序可能会在主视图 Controller 的 viewDidAppear 方法中动态创建相机字段。如果您将主视图 Controller 设置为相机字段的委托(delegate),那么当它离开选取器时,它仍然会调用 viewDidAppear。必须避免这种情况,否则您将失去形象。

真正有趣的是,这只发生在 iPhone 6 和 6 plus 上。所有其他设备都不会尝试重新加载 View ……去看看吧。

关于ios - UIImagePicker 仅适用于 iPhone 6 plus 上的前置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28049286/

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