簡體   English   中英

當關閉iOS 8時ImagePicker刪除視圖

[英]ImagePicker removing views when dismissed iOS 8

我的應用程序由一個中央視圖控制器構成,該控制器將3到4個子視圖添加到主視圖。 在添加的視圖控制器之一中,我向用戶展示了一個攝像頭。 當我關閉圖像選擇器時,除我要展示相機的那個子視圖(視圖控制器)之外的所有子視圖都消失了。 我認為這可能與應用程序的結構和視圖堆棧有關。 當在iPhone上運行iOS 8和在iPad上運行iOS 7時,該應用程序運行良好。 僅當我在iPad上運行iOS 8時,才遇到此問題。 我確保代碼遵循apple文檔中有關如何顯示和關閉圖像選擇器的內容。 這是用於呈現圖像選擇器的代碼。

 -(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是我拍照的地方。 當我關閉時,除查詢視圖控制器外,所有視圖都消失了,而查詢視圖控制器恰好占據了整個屏幕(以前沒有)。 讓我知道是否需要添加更多信息! 謝謝

因此,一般的問題是您的中央視圖控制器正在向其自身添加其他視圖控制器的視圖。 您不能這樣做-破壞了視圖控制器的封裝。 當您違反封裝時,東西就會破裂。 (這是一個模糊的陳述,但是100%是:-p)不幸的是,您要么需要在黑暗中刺入以找到使之起作用的hack,要么將其重新划分為尊重封裝的問題。 如果將來需要維護此代碼,則后者可能會更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM