1

我正在尝试打开一个UIImagePickerControllerSourceTypeCamera小的弹出子视图,但是每次我尝试这个时它都会进入全屏摄像头......这是我第一次尝试使用摄像头我已经阅读了开发者网站中的所有文档我只是找不到任何解释如何做我想做的事情的东西。

下面是我的 startCamera 方法,在该方法中我创建了一个子视图,然后创建 cameraView 将 cameraView 添加到小子视图中,然后我将其加载到主 UIView .... 但是如上所述,它每次都会全屏显示 :(

任何使这个 cameraView 看起来像一个小的弹出视图的帮助将不胜感激。

#pragma StartCamera
- (IBAction)startCamera:(id)sender {

    if (isCameraViewLoaded == NO) {
        // Load View for camera
        cameraView = [[UIView alloc] initWithFrame:CGRectMake(100.0, 100.0, 200.0, 100.0)];
        cameraView.backgroundColor = [UIColor greenColor];


        // imagepicker stuff
        // check for rear facing camera to continue
        if( [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
        {
            // load imagePickController into subview
           UIImagePickerController *imagePickController=[[UIImagePickerController alloc]init];
            imagePickController.sourceType=UIImagePickerControllerSourceTypeCamera;
            imagePickController.delegate=self;
            imagePickController.allowsEditing=TRUE;
            imagePickController.modalPresentationStyle = UIModalPresentationCurrentContext;
            [cameraView addSubview:imagePickController.view];
        }
        else {
            // if there is no camera on the device give warning
            UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:@"Incompatible Device" message:@"Sorry, This feature requiers a rear facing camera" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

            [noCameraAlert show];
        }

        // pass camera View to mainview
        [self.view addSubview:cameraView];
        isCameraViewLoaded = YES;
    }else{
        [cameraView removeFromSuperview];
        isCameraViewLoaded = NO;
    }

}
4

0 回答 0