gpt4 book ai didi

ios - UIImagePicker 被选中后重新出现

转载 作者:行者123 更新时间:2023-11-28 19:47:01 26 4
gpt4 key购买 nike

我有一个 UIImagePicker,它在我选择图像后不断出现。我的代码正在检查摄像头,然后根据模拟器中没有摄像头的事实显示 UIImagePicker

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
self.imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self clear];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[self dismissViewControllerAnimated:YES completion:nil];
}

我需要强制重新加载我的初始 View 吗?有没有更聪明的方法来做到这一点?

编辑

我向导航栏添加了一个栏按钮,并在该操作上触发了我的代码。这解决了问题,似乎是一种更好的方法。

最佳答案

可能 viewWillAppear 每次 UIImagePickerController 消失时都会被调用 - 因为您放置代码的 View Controller 再次变得可见。

您可以尝试在 viewDidLoad 中创建 UIImagePickerController,或者使用 bool 属性来检查它是否是第一次调用它。

关于ios - UIImagePicker 被选中后重新出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31547683/

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