1

我正在开发一个应用程序,我需要在其中保持打开全屏摄像头并在其上添加一个按钮(右下角)。我用谷歌搜索但找不到任何健康的解决方案。提前致谢。祝你有美好的一天。 已编辑

    - (void) showCameraUI {
    [self startCameraControllerFromViewController: self
                                    usingDelegate: self];
}

- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
                                   usingDelegate: (id <UIImagePickerControllerDelegate,
                                                   UINavigationControllerDelegate>) delegate {


    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeCamera] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    NSLog(@"Start Camera Controller method...");
    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Displays a control that allows the user to choose picture or
    // movie capture, if both are available:
    cameraUI.mediaTypes =
    [UIImagePickerController availableMediaTypesForSourceType:
     UIImagePickerControllerSourceTypeCamera];

    // Hides the controls for moving & scaling pictures, or for
    // trimming movies. To instead show the controls, use YES.
    cameraUI.allowsEditing = NO;

    cameraUI.delegate = delegate;

    [controller presentModalViewController: cameraUI animated: YES];
    return YES;
}

PS:我还在UINavigationControllerDelegate,UIImagePickerControllerDelegate头文件中添加了协议,但它仍然没有打开相机并显示项目的默认视图。

4

1 回答 1

2

你可以简单地使用像波纹管这样的相机来捕捉图像,我在我的代码中使用了这个波纹管方法:-

-(void)btnCemeraOpen
{
        UIImagePickerController * picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;


        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {       
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
                [self presentModalViewController:picker animated:YES];
        }
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissModalViewControllerAnimated:YES];
    yourImageView.image = [info valueForKey:@"UIImagePickerControllerOriginalImage"];
    if(yourImageView==nil)
    {

    }
    else
    {
      //DO logic

    }

    return;
}   
于 2013-03-14T07:05:43.060 回答