有誰知道如何啓用相機模式下的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