如何在Xcode中打开全屏摄像头

时间:2013-03-14 06:10:25

标签: iphone ios xcode camera

我正在开发一款应用程序,我需要打开全屏相机,并在其上添加一个按钮(右下角)。我用谷歌搜索,但找不到任何健康的解决方案。提前致谢。祝你有美好的一天。 的被修改

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

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

1 个答案:

答案 0 :(得分:2)

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

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