iPhone中圖庫類UIImagePickerController

在app中想得到手機中的圖片,可使用類UIImagePickerController,經過這個類能夠得到手機中的圖片。使用這個類得到圖片,都須要遵照UIImagePickerControllerDelegate,UINavigationControllerDelegate協議,在選擇圖片完畢後使用代理方法- (void)imagePickerController:(nonnull UIImagePickerController *)picker didFinishPickingImage:(nonnull UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo便可得到選擇的圖片app

 

 //得到圖片  在圖片選擇器中選擇代理

    UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];圖片

    [self presentViewController:pickerController animated:YES completion:nil];it

    

    //設置UIImagePickerControllerDelegate的代理io

    pickerController.delegate = self;List

 

- (void)imagePickerController:(nonnull UIImagePickerController *)picker didFinishPickingImage:(nonnull UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo{方法

    [self.imageList addObject:image];im

    [self.collectionView reloadData];協議

    

    [self dismissViewControllerAnimated:YES completion:nil];animate

}

相關文章
相關標籤/搜索