简体   繁体   English

iPhone Camera App-如何保持在相机视图中?

[英]iPhone Camera App - how to stay in Camera view?

I've implemented the camera inside of my app with the default showsCameraControls = YES, and the issue I am having is when the user confirms that the image is a keeper, it dismisses the camera with [self.delegate didFinishWithCamera]. 我已经使用默认的showCameraControls = YES在我的应用程序内部实现了相机,而我遇到的问题是,当用户确认图像为守护者时,它使用[self.delegate didFinishWithCamera]取消了相机。 I would like to remain in the Camera view until the user is done taking photos. 我想保留在“相机”视图中,直到用户完成拍照为止。 Without [self.delegate didFinishWithCamera], the app hangs after the user confirms they want to keep the photo and never returns back to the live camera feed. 如果没有[self.delegate didFinishWithCamera],则该应用程序会在用户确认要保留照片后挂起,并且永不返回实时摄像机供稿。 How do I remain in the camera view? 如何保留在相机视图中? Your help is appreciated! 感谢您的帮助!

@implementation PHFPhotoOverlayVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.imagePickerController = [[UIImagePickerController alloc] init];
        self.imagePickerController.delegate = self;
    }
    return self;
}

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
    self.imagePickerController.sourceType = sourceType;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        self.imagePickerController.mediaTypes =
            [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
        self.imagePickerController.showsCameraControls = YES;

#if false
        if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
        {
            CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
            CGRect newFrame = CGRectMake(0.0,
                                         CGRectGetHeight(overlayViewFrame) -
                                         self.view.frame.size.height - 10.0,
                                         CGRectGetWidth(overlayViewFrame),
                                         self.view.frame.size.height + 10.0);
            self.view.frame = newFrame;
            [self.imagePickerController.cameraOverlayView addSubview:self.view];
        }
#endif
    }
}


#pragma mark -
#pragma mark UIImagePickerControllerDelegate

- (void)    imagePickerController:(UIImagePickerController *)picker
    didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.imagePickerController.mediaTypes =
        [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
    self.imagePickerController.showsCameraControls = YES;


    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    if (self.delegate)
        [self.delegate didTakePicture:image];

    [self.delegate didFinishWithCamera];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self.delegate didFinishWithCamera];
}

@end

In order to achieve this, you will have to implement your own method for taking a picture, since this default button causes the view to dismiss itself. 为了实现这一点,您将必须实现自己的拍照方法,因为此默认按钮会导致视图自行关闭。

Obviously, you can do this by setting showsCameraControls=NO, but then you'd have to recreate all the other functionality that you still want. 显然,您可以通过设置showsCameraControls = NO来做到这一点,但是随后您将不得不重新创建仍然需要的所有其他功能。

I've never done this, but it should be possible to leave showsCameraControls=YES and use the cameraOverlayView to simply layer an identical "Take Picture" button over the existing one. 我从来没有做过,但是应该可以离开showsCameraControls = YES并使用cameraOverlayView在现有按钮上简单地层叠一个相同的“拍摄图片”按钮。 If you do that, you just need to have that button call the method -takePicture from the instance of your UIImagePickerViewController. 如果这样做,则只需要让该按钮从UIImagePickerViewController实例中调用方法-takePicture。

Hopefully that's enough, feel free to comment and ask for any clarification. 希望就足够了,随时发表评论并要求任何澄清。

You're going to need to implement a custom camera - check out Apple's SquareCam example 您将需要实现自定义相机-查看Apple的SquareCam示例

You'll be using AVFoundation and will be able to implement any kind of custom behavior when a photo is taken (including just staying on that camera page) - you'll even have to save it to the Photo Library yourself (the SquareCam example shows you how to do this). 您将使用AVFoundation,并且能够在拍摄照片时实现任何类型的自定义行为(包括仅停留在该相机页面上)-您甚至必须将其保存到照片库中(SquareCam示例显示您如何执行此操作)。 This also means that if you need the crop/resize controls, you'll have to create them yourself, as well as a picker view (grid gallery view) if you want the user to be able to review their photos after taking them. 这也意味着,如果需要裁剪/调整大小控件,则必须自己创建;如果希望用户在拍摄后能够查看其照片,则必须创建一个选择器视图(网格画廊视图)。

It's probably around intermediate level stuff - took me a few days to implement, but if your app is in any way focused on photos, this is definitely the way to go. 它可能是围绕中级水平的东西-我花了几天的时间来实现,但是如果您的应用程序以任何方式都专注于照片,那肯定是要走的路。 Gives you complete control of the camera UI and behavior. 使您可以完全控制相机的UI和行为。

Oh, and yeah you'll have to implement the flash button, shutter button, shutter effect, tap to focus, and anything else yourself too. 哦,是的,您还必须实现闪光灯按钮,快门按钮,快门效果,点击对焦以及您自己的其他任何功能。 AVFoundation basically gives you a straight pipe to the camera lens (figuratively). AVFoundation基本上为您提供了一条通向摄像机镜头的直管(如图所示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM