gpt4 book ai didi

ios - 在打开的相机上呈现相机胶卷 UIImagePickerController

转载 作者:技术小花猫 更新时间:2023-10-29 10:59:30 24 4
gpt4 key购买 nike

在我的应用程序中,我在打开的相机上有一个 cameraOverlayView,带有相机按钮的自定义控件。该应用允许用户在关闭相机之前拍摄多张照片,因此快门按钮不会调用 dismissViewControllerAnimated,而是在您完成拍摄时调用关闭按钮。

现在,相机覆盖层上的按钮之一是画廊按钮,允许用户选择保存的图像而不是拍摄新图像。我尝试了两种不同的方法来完成这项工作,但都失败了。

第一种方法

使用当前呈现叠加层的相同 UIImagePickerController 实例并将 sourceType 切换为库。它确实显示了画廊,但是当点击一张照片时,我不能在不关闭整个叠加层的情况下关闭厨房。

第二种方法

创建一个单独的 UIImagePickerController 实例,将 sourceType 设置为 gallery 并尝试调用 presentViewController,然后失败并显示警告:

"Warning: Attempt to present on whose view is not in the window hierarchy!"

有人能解决这个问题吗?这可能吗?

最佳答案

试试这个~~我认为这是你的目标。

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIImagePickerController *imagePicker;

@end

@implementation ViewController

@synthesize imagePicker = _imagePicker;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}


- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];

sleep(2);

_imagePicker = [[UIImagePickerController alloc] init];
[_imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[_imagePicker setDelegate:self];

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10, 50, 100, 30)];
[button setTitle:@"Library" forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor darkGrayColor]];
[button addTarget:self action:@selector(gotoLibrary:) forControlEvents:UIControlEventTouchUpInside];

[_imagePicker.view addSubview:button];

[self presentViewController:_imagePicker animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(IBAction)gotoLibrary:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker.view setFrame:CGRectMake(0, 80, 320, 350)];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
[imagePicker setDelegate:self];

[_imagePicker presentViewController:imagePicker animated:YES completion:nil];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
@end

关于ios - 在打开的相机上呈现相机胶卷 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14330159/

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