gpt4 book ai didi

ios - 相机在 IOS 中不工作

转载 作者:行者123 更新时间:2023-11-29 01:13:10 27 4
gpt4 key购买 nike

我已经实现了以下操作,相机已打开,但应用程序崩溃了,有时当打开并拍照时,应用程序崩溃了,日志仅显示“快照尚未渲染的 View 会导致空快照。确保您的 View 在屏幕更新之前至少渲染过一次快照或快照后收到内存警告。”

我用于从图库中获取图像及其工作的相同功能。

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:      (NSInteger)buttonIndex{
if (buttonIndex==0) {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Alert"
message:@"Device has no Camera!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

[myAlertView show];

}else{

[self performSelector:@selector(loadCamera) withObject:nil afterDelay:1.0];

}
}
}


-(void)loadCamera{

picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion:NULL];
}

谁能帮忙。

最佳答案

通过以下代码解决:

-(void)loadCamera{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
dispatch_async(dispatch_get_main_queue(), ^{

picker1 = [[UIImagePickerController alloc] init];
picker1.delegate = self;
picker1.allowsEditing=YES;
picker1.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker1 animated:YES completion: nil];

});
}
}

此代码适用于 iOS 9.2 和 xCode 7.2

关于ios - 相机在 IOS 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523246/

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