在 .h 类中保留一个UIImagePickerController
obj(例如imagePicker
)
分配 obj 一次(例如在 中viewDidLoad
)
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self.view addSubview:imagePicker.view];
imagePicker.view.hidden = YES;
imagePicker.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
imagePicker.view.bounds = CGRectMake(0,20,self.view.frame.size.width, self.view.frame.size.height);
在didFinishPickingMediaWithInfo
if([[info valueForKey:UIImagePickerControllerMediaType] isEqualToString:@"public.image"]){
imagePicker.view.hidden = YES;
}
当你想展示imagePickerView
正义时
imagePicker.view.hidden = NO;