启用UIImagePickerController上的照片库按钮

时间:2011-12-16 01:41:06

标签: ios uiimagepickercontroller iphone-4

有人知道如何在相机模式下启用UIImagePickerController上的相册按钮吗?就像iphone上的相机应用程序如何在图像和视频拍摄之间切换一样,还有按钮来查看照片库?

4 个答案:

答案 0 :(得分:14)

这可以通过以下几行完成:

- (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;
}

答案 1 :(得分:7)

我担心这不能以那么简单的方式完成(只需启用或禁用某些魔术功能)。对于一些简单的要求,您可以使用cameraOverlayViewshowsCameraControls来实现。

如果您想在照片/视频模式之间切换,我想您可以查看此演示:http://developer.apple.com/library/ios/#samplecode/AVCam/Introduction/Intro.html

答案 2 :(得分:3)

这是一个示例应用程序和非常简单的库,可让您像Facebook一样获取“拍照”或“从库中选择”。 https://github.com/fulldecent/FDTake

答案 3 :(得分:1)

Swift2版本的@epsilontik代码:

<html>
  <head>
    <title>Your responses have been submitted.</title>
    Thank you. You have now completed the survey.
  </head>
  <?php
    $data = array("name","age","sex","ethnicity","race");

    $file = "/demo.csv";
    $current = file_get_contents($file);
    $current .= "\n" . implode(",",$data);
    file_put_contents($file, $current);
    ?>
</html>