UIImagePickerController在我自己的UINavigationalController上推送?

时间:2012-12-29 05:59:06

标签: iphone ios cocoa-touch uiimagepickercontroller

我正在尝试将UIImagePickerController设置为UIImagePickerControllerSourceTypeCamera(即,当它允许用户拍照时)并将其推送到我自己的UINavigationalController,但它不会工作(无法将UINavigationalController推送到另一个UINavigationalController)。

我想知道,无论如何要制作这个相机模块的自定义版本,就像使用UIImagePickerControllerSourceTypePhotoLibrary UIImagePickerController ALAssets一样?我只是不想将相机作为模态视图弹出,并希望将其推送到我自己的UINavigationalController

3 个答案:

答案 0 :(得分:1)

您可以使用AVFoundation自定义相机。

请参阅Sample AVCam了解如何使用AVFoundation。

答案 1 :(得分:1)

你的主要问题是UIImagePickerController本身就是一个UINavigationController,所以把它推到导航控制器上会遇到问题(正如你已经发现的那样)

正如普林斯所提到的,最好的办法是使用AVFoundation创建自己的。缺点是你(默认情况下)失去相机应用程序的漂亮功能,如触摸对焦,捏缩放等等,但这些都可以自己添加。

查看this tutorial,它为您提供了有关如何使用AVFoundation库的很好的解释,并且还向您展示了如何在相机屏幕上添加叠加等内容。然后你可以很容易地在google / stackoverflow上找到如何添加点击聚焦的东西:)

答案 2 :(得分:0)

我有同样的问题,但我这样解决了。

如果你拍照
1)从相机(在UINavigationcontroller中打开) 2)来自Gallery(用于ipad打开为UIpopovercontroller& for iphone open as nvigationcontroller)

首先设置代理

@interface camera : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIPopoverControllerDelegate>

从相机获取图片后

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            UIImagePickerController *imagePicker =
            [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;
            imagePicker.sourceType =
            UIImagePickerControllerSourceTypeCamera;
            imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                      (NSString *) kUTTypeImage,
                                      nil];

            imagePicker.allowsEditing = YES;

            imagePicker.wantsFullScreenLayout = YES;

            [self presentViewController:imagePicker animated:YES completion:nil];
            newMedia = YES;
            iscamera = 0;
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error to access Camera"
                                                            message:@""
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];

        }

&安培; 从图库中获取图片

 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *_picker=nil;
        if (popoverController) {
            [popoverController dismissPopoverAnimated:NO];

        }
        _picker = [[UIImagePickerController alloc] init];
        _picker.delegate = self;        
        _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        _picker.wantsFullScreenLayout = YES;

        //[popoverController presentPopoverFromBarButtonItem:sender
                               //   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

           [self presentViewController:_picker animated:YES completion:nil];


        } else
        {
            popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
            [popoverController setDelegate:self];
            [popoverController presentPopoverFromRect:btn.frame
                                               inView:self.view
                             permittedArrowDirections:UIPopoverArrowDirectionLeft
                                             animated:YES];
        }
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error access photo library"
                                                        message:@"your device non support photo library"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }

两种结果都是您参与委托方法

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{

}