我正在尝试使用 UIImagePickerController 从照片库中选择多个图像,我希望可以在照片选择器底部添加一个 subview ,使其看起来像这个应用程序:
有简单的方法可以做到吗?我的代码目前只以标准方式弹出图像,但我只在加载 6 张图像时关闭 Controller
重要的是,如果我可以向照片选择器 View 添加一个小 View /工具栏,就像示例中所做的那样,那么我可以完成剩下的工作
- (void)getMediaFromSourceUIImagePickerControllerSourceType)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)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info{
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType]; //record media type
//if media type is image
if ([lastChosenMediaType isEqualNSString *) 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];
}
}
使用诸如将 UIImagePickerController 向上移动并在下方显示所选图像之类的技巧的主要原因是, Assets 库替代方案会涉及到用户被要求访问位置,因为有关照片拍摄地点的信息在图像元数据中可用.
在 iOS 6 中,系统会询问用户是否要允许应用访问他们的照片(而不是位置),并且对于 Assets 库方法和 UIImagePickerController 方法都会询问您这个问题。
因此,我认为像上面这样的黑客已经接近了它们的用处。 Here is a link to a library providing selection of multiple images using the Assets library还有其他的。
关于iphone - UIImagePickerController 选择多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13093143/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |