我正在尝试使用 UIImagePickerController 从照片库中简单地选择多个图像,我希望我可以在照片选择器的底部添加一个子视图,这样它看起来就像这个应用程序一样:
有一个简单的方法可以做到吗?我的代码目前仅以标准方式弹出图像,但仅在加载 6 张图像时关闭控制器
重要的是,如果无论如何我可以向照片选择器视图添加一个小视图/工具栏,就像示例中所做的那样,那么我可以完成剩下的工作
- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType{
//get all available source types
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
//if source type available and supported media type is not null
if ([UIImagePickerController isSourceTypeAvailable:sourceType
&& [mediaTypes count] > 0]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
//picker.mediaTypes = mediaTypes; //allow videos
picker.delegate = self;
picker.sourceType = sourceType; //set source type to the given type
/** WANT TO ADD A CUSTOM VIEW IN THE PHOTO PICKER VIEW **/
[self presentViewController:picker animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error accessing media"
message:@"Device doesn't support that media type"
delegate:nil
cancelButtonTitle:@"Drat !"
otherButtonTitles: nil];
[alert show];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType]; //record media type
//if media type is image
if ([lastChosenMediaType isEqual:(NSString *) kUTTypeImage]) {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; //load image
//save the image if is from camera shot
if (imageOrVideoSourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum (chosenImage, nil, nil , nil);
}
[images addObject:chosenImage]; //add to image list
imageNum++;
}
changeImageOrVideo = true;
if(imageNum >= 5){
[picker dismissViewControllerAnimated:YES completion:nil];
}
}