有谁知道如何启用相机模式下的UIImagePickerController上的相册按钮?就像iPhone上的相机应用程序可以在图像和视频拍摄之间切换,并且还具有查看照片库的按钮?启用UIImagePickerController上的照片库按钮
回答
恐怕不能以这种简单的方式完成(只是启用或禁用某些魔术功能)。对于一些简单的要求,您可以使用cameraOverlayView和showsCameraControls来实现。
如果要照片/视频模式之间进行切换,我想你可以检查此演示:http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html
这可以通过以下行来完成:
- (void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated {
if (imagePickerController.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showCamera:)];
viewController.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:button];
} else {
UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(showLibrary:)];
viewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObject:button];
viewController.navigationItem.title = @"Take Photo";
viewController.navigationController.navigationBarHidden = NO; // important
}
}
- (void) showCamera: (id) sender {
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
- (void) showLibrary: (id) sender {
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
这不会改变相机控制,而是将相机导航条添加到相机窗口的顶部。这可能是也可能不是你想要的,但我不认为这是OP的想法。 – DaGaMs 2012-06-26 07:17:16
伟大的解决方案。请记住检查相机源是否真的可用。例如: if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ self.picker.sourceType = UIImagePickerControllerSourceTypeCamera; } – EsbenB 2013-05-28 13:26:41
下面是一个示例应用程序和非常简单的图书馆,可以让你像Facebook那样获取拍照或从图书馆中选择。 https://github.com/fulldecent/FDTake
我已经做了这个调整苹果的PhotoPicker示例应用程序。我已经删除了所有的相机控制,并添加了我自己的按钮。点击后,UIImagePickerControllerSourceType被设置为UIImagePickerControllerSourceTypePhotoLibrary。
对于我来说,棘手的部分是在图像被选中后“解散”(可能在技术上是错误的词)照片库。我通过将源类型设置回UIImagePickerControllerSourceTypeCamera来做到这一点。这将带回相机重叠视图。
ViewController.h
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import <ImageIO/ImageIO.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate> {
//
}
@property (nonatomic, strong) UIImagePickerController *imagePicker;
- (IBAction)uploadNewPhotoTapped:(id)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
//Other code
- (IBAction)uploadNewPhotoTapped:(id)sender {
UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init];
//You can use isSourceTypeAvailable to check
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePickController.sourceType=UIImagePickerControllerSourceTypeCamera;
imagePickController.showsCameraControls=YES;
// self.usingPopover = NO;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {//Check PhotoLibrary available or not
imagePickController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
imagePickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) //Check front Camera available or not
imagePickController.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
//else //!!!!!!!!!!!exception
imagePickController.delegate=self;
imagePickController.allowsEditing=NO;
[self presentModalViewController:imagePickController animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *originalImage=[info objectForKey:UIImagePickerControllerOriginalImage];
//Do whatever with your image
NSData *data = UIImageJPEGRepresentation (
originalImage,
1.0
);
[self dismissModalViewControllerAnimated:YES];
}
// Other code
@end
Swift2版本的@epsilontik代码:
//mediaPicker is your UIImagePickerController
func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
if(mediaPicker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary){
let button = UIBarButtonItem(title: "Take picture", style: UIBarButtonItemStyle.Plain, target: self, action: "showCamera")
viewController.navigationItem.rightBarButtonItem = button
}else{
let button = UIBarButtonItem(title: "Choose picture", style: UIBarButtonItemStyle.Plain, target: self, action: "choosePicture")
viewController.navigationItem.rightBarButtonItem = button
viewController.navigationController?.navigationBarHidden = false
viewController.navigationController?.navigationBar.translucent = true
}
}
func showCamera(){
mediaPicker.sourceType = UIImagePickerControllerSourceType.Camera
}
func choosePicture(){
mediaPicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
}
- 1. 如何在UIImagePickerController上添加照片库按钮?
- 2. 使用UIImagepickercontroller从iPhone照片库获取照片
- 3. 的UIImagePickerController视频时长 - 照片库
- 4. 向UIImagePickerController的工具栏添加“从照片库中选择”按钮
- 5. 的UIImagePickerController与图片库使用固定大小的照片
- 6. ios UIImagePickerController拍照按钮标题
- 7. 使用的UIImagePickerController检索照片库中选择图片
- 8. 在WebView按钮上调用iPhone照片库点击
- 9. 允许使用的UIImagePickerController直至取消按钮拍摄照片点击
- 10. 西班牙语支持重拍和使用UIImagePickerController的照片按钮
- 11. jquery编码照片库的上一个和下一个按钮
- 12. 不要使用的UIImagePickerController获取照片
- 13. UIImagePickerController按钮
- 14. 从按钮中添加图片库中的图片并在按钮上显示照片
- 15. 使用UIImagePickerController选择多张照片
- 16. iPhone上的按钮点击图片应该存储在照片库
- 17. 无需使用uiimagepicker启动照片库
- 18. iOS。用音量按钮捕捉照片
- 19. 如何启用了“拍照”按钮,而在相机胶卷中选择照片
- 20. 的UIImagePickerController - 得到的照片库中选择图像
- 21. 从图库图片中的“分享”按钮分享照片/照片到我的离子2应用程序
- 22. UIImagePickerController - 从照片库中选择背景中的视频
- 23. 使用UIImagePickerController选择并上传照片到服务器。
- 24. 删除照片后,UIImagePickerController崩溃
- 25. UIImagePickerController:如何拍摄1张照片?
- 26. UIIMagePickerController +相机+全屏捕捉照片
- 27. 照片中的图片按钮被禁用
- 28. 如果不允许UIImagePickerController访问照片库,请显示UIActionSheetUser
- 29. UIImagePickerController拍照按钮不起作用,直到长按或点击很多次
- 30. 不能使用IOS中的“使用过的照片”swift UIImagePickerController
啊确定。谢谢!! – MBU 2011-12-16 19:05:54