解除iOS 8时删除视图的ImagePicker

时间:2014-11-12 22:12:26

标签: ios image ios8

我的应用程序采用中央视图控制器构建,可在主视图中添加3到4个子视图。在其中一个添加的视图控制器中,我向用户展示了一个摄像头。当我关闭图像选择器时,除了我呈现相机(视图控制器)之外的每个子视图都会消失。我认为这可能与应用程序的结构和视图堆栈有关。在iPhone和iOS 7上运行iOS 8时,该应用程序运行正常。我只有在iPad上运行iOS 8时才遇到这个问题。我确保代码遵循苹果文档,介绍如何呈现和关闭图像选择器。这是用于呈现图像选择器的代码。

 -(IBAction)photoButtonPressed:(id)sender
{

    // Prompt for camera or photo library
    // Retrieve image and set it as this button's default image
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];

        imagePicker.delegate = self;

        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage, nil];

        imagePicker.allowsEditing = NO;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen; //play around with this

       [self presentViewController:imagePicker animated:YES completion:nil];

    } else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera not found" message:@"There is no camera available on this device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

用于解雇的代码

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        CGSize scaleSize = CGSizeMake(1024.0f, 1280.0f);
        UIImage *capturedImage;

        // Handle a still image capture
        capturedImage = (UIImage *) [info objectForKey:
                                     UIImagePickerControllerOriginalImage];

        [self dismissViewControllerAnimated:YES completion:nil];


        if (capturedImage) {
            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
                photoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
                photoEntity = nil;

                [self.takePhotoButton setImage:[UIImage imageWithData:photoData ] forState:UIControlStateNormal];


                if ([self isAnyButtonSelected] || ![_answerTextField.text isEqualToString:@""] || !_questionBoolean.hidden) {
                    [Tools enableControl:_saveButton];
                }


            } else {
                newPhotoData = UIImageJPEGRepresentation([capturedImage resizedImage:scaleSize interpolationQuality:kCGInterpolationHigh], 5);
                photoEntity = nil;
            }
        }
    }

在这里,我尝试使用此方法中的父视图和控制器。我能够让应用程序返回中央视图控制器减去负责拍摄照片的当前视图控制器。唯一的问题是应用程序的触摸现在已禁用,我缺少一个视图。

- (void) imagePickerControllerDidCancel: (UIImagePickerController *) picker
{
//   [self willMoveToParentViewController:nil];
//    [picker.view removeFromSuperview];
//   [picker removeFromParentViewController];
    [self dismissViewControllerAnimated:YES completion:nil];

}

我打算发布照片,但我目前无法发布,因为我是新手来堆叠溢出。任何帮助,将不胜感激。谢谢!

好的,所以应用程序不使用故事板,但它使用的是xib文件。它是继承的代码,应用程序是几年前创建的。有多个视图控制器具有多个视图。有一个中央视图控制器,其中所有其他视图控制器都添加到中央视图。

[self.view addSubview:_catViewController.tableView];
[self.view addSubview:_listViewController.tableView];
[self.view addSubview:_queryViewController.view];
[self.view bringSubviewToFront:_queryViewController.view];

queryViewController是我拍摄照片的地方。当我解雇每个视图时,除了查询视图控制器,它恰好占用整个屏幕(之前没有)。如果我需要添加更多信息,请告诉我们!感谢

1 个答案:

答案 0 :(得分:0)

因此,一般问题是您的中央视图控制器正在将其他视图控制器的视图添加到自身。你不能这样做 - 它打破了视图控制器的封装。当你违反封装时,东西就会破裂。 (这是一个模糊的陈述,但100%是真的:-p)不幸的是,你要么在黑暗中刺中找到一个黑客来使其工作,要么重新分配问题以尊重封装。如果您将来需要维护此代码,后者可能会更好。