【问题标题】:UIImagePickerController pushed on my own UINavigationalController?UIImagePickerController 推送到我自己的 UINavigationalController 上?
【发布时间】:2012-12-29 05:59:05
【问题描述】:

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

我想知道,是否可以制作此相机模块的自定义版本,就像您可以使用 ALAssets 使用 UIImagePickerControllerSourceTypePhotoLibrary UIImagePickerController 一样?我只是不想将相机作为模态视图弹出,而是想自己推送它UINavigationalController

【问题讨论】:

    标签: iphone ios cocoa-touch uiimagepickercontroller


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您的主要问题是 UIImagePickerController 本身就是一个 UINavigationController,因此将其推送到导航控制器上会有问题(正如您已经发现的那样)

      正如 Prince 所说,最好的办法是使用 AVFoundation 来创建自己的。缺点是您将(默认情况下)失去相机应用程序的不错功能,例如触摸对焦、捏合缩放等,但这些都可以自己添加。

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

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题,但我用这种方法解决了。

        如果你拍照
        1)来自相机(在两者都打开为 UINavigationcontroller) 2) 来自 Gallery(对于 ipad 作为 UIpopovercontroller 打开 & 对于 iphone 作为 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
        {
        
        }
        

        【讨论】:

          猜你喜欢
          • 2015-01-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-06-18
          • 1970-01-01
          相关资源
          最近更新 更多