我正在开发通用应用程序,想打开相机。现在我可以在 iphone 上使用 UIimagePickerController 打开相机,但在 iPad 上它不起作用。我搜索了解决方案并找到了这段代码
self.cameraController = [[UIImagePickerController alloc] init];
self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.cameraController.showsCameraControls = NO;
self.cameraController.navigationBarHidden = YES;
self.cameraController.wantsFullScreenLayout = NO;
[self.cameraController setCameraOverlayView:ar_overlayView];
[ar_overlayView setFrame:self.cameraController.view.bounds];
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
if([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0 && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self presentViewController:self.cameraController animated:YES completion:nil];
}];
}
else{
[vc presentViewController:self.cameraController animated:YES completion:nil];
}
还遵循了一些教程,例如
TechnoTopia Post但没有找到任何运气。我已经在 iphone 5s 上测试过它并且工作正常但在 iPad mini 上相机没有出现。任何帮助将不胜感激!
最佳答案
在 iPad 上试试这个
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
UIImagePickerController* picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.allowsEditing=YES;
picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}];
}
else if (buttonIndex==1)
{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
UIImagePickerController* picker=[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.allowsEditing=YES;
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];}];
}
}
关于ios - 运行 iOS 8.2 的 ipad 中不显示相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32754754/