单击捕获相机时,UIImagePickerController窗口关闭

时间:2018-11-27 07:06:27

标签: ios xcode ipad uiimagepickercontroller uitapgesturerecognizer

单击“捕获照相机”图标时,UIImagePickerController窗口关闭。我提出了两个UIViewController作为FormSheet。如果用户在这两个屏幕之外单击,我添加了UITapGestureRecognizer来关闭这两个屏幕。

我在这里附上我的代码

主屏幕的viewDidLoad:

UITapGestureRecognizer *tapBGGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(settingsBGTapped:)];
[tapBGGesture setNumberOfTapsRequired:1];
tapBGGesture.cancelsTouchesInView = NO;
tapBGGesture.delegate = self;
[self.view.window addGestureRecognizer:tapBGGesture];

- (void)settingsBGTapped:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded)
{

    CGPoint location = [sender locationInView: self.view];

    //Convert tap location into the local view's coordinate system. If outside, dismiss the view.
    if (![self.presentedViewController.view pointInside:[self.presentedViewController.view convertPoint:location fromView:self.view.window] withEvent:nil])
    {
        if(self.presentedViewController) {

            [self dismissViewControllerAnimated:YES completion:nil];
        }
    } 
}
}

在主屏幕上单击一个按钮时,显示第一个屏幕。

点击主屏幕按钮:

ViewController1 *vc1 = [[ViewController1 alloc] init];
vc1.modalPresentationStyle = UIModalPresentationFormSheet;
vc1.preferredContentSize = CGSizeMake(690, 600);
[self presentViewController:vc1 animated:YES completion:nil];

在第一个屏幕上单击一个按钮时,将显示第二个屏幕。

单击第一屏按钮:

ViewController2 *vc2 = [[ViewController2 alloc] init];
vc2.delegate = self;
vc2.modalPresentationStyle = UIModalPresentationFormSheet;
vc2.preferredContentSize = CGSizeMake(600, 600);

[self presentViewController:vc2动画:是完成:无];

在第二个屏幕中单击一个按钮:

- (IBAction)takePhotoClicked:(id)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:NULL];

}

当UIImagePickerController上的“捕获图标”按钮时,为什么UIImagePickerController窗口关闭。

请帮助任何人解决此问题。

注意:在iOS 11之前的以前的iOS版本上运行正常

0 个答案:

没有答案