gpt4 book ai didi

ios - 在 UIView 中使用 UIImagePickerController

转载 作者:可可西里 更新时间:2023-11-01 03:06:41 27 4
gpt4 key购买 nike

我有一个按钮,当我点击它时会显示相机(完美运行)

- (IBAction)getPhoto:(id)sender
{
NSLog( @"Button clicked!" );
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}

else { // IF the device doesn't have a camera, so use the photos album
[imagePicker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
}

[self addSubview:imagePicker.view];
}

之后我可以拍摄图像等 - 但是当我单击“使用”时:我的方法没有发生任何事情:图像选择器不会关闭它自己:应用程序什么都不做,我正在尝试使用我刚刚拍摄的图像并将其显示在屏幕上的 CGRect 中。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:NULL];

UIImageView *patientImage = [[UIImageView alloc] init];
patientImage.frame = CGRectMake(625, 25, 83, 103);

UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.patientImage.image = chosenImage;
}

即使我在没有拍照的情况下点击取消按钮,imagePicker(相机界面)也不会自行关闭

如有任何帮助、建议或指导,我们将不胜感激。

最佳答案

You shouldn't be doing the "addSubview" thing up there而是这样做:

[self presentViewController:imagePicker animated:YES completion:nil];

关于ios - 在 UIView 中使用 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17232270/

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