programing

iOS 8 렌더링되지 않은 뷰의 스냅샷은 빈 스냅샷이 됩니다.

stoneblock 2023. 4. 24. 21:09

iOS 8 렌더링되지 않은 뷰의 스냅샷은 빈 스냅샷이 됩니다.

iOS 8에서는 지금까지 카메라에서 이미지를 캡처하는 데 어려움을 겪고 있습니다.

UIImagePickerController *controller=[[UIImagePickerController alloc] init];
controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
controller.delegate=(id)self;
controller.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:controller animated:YES completion:nil];

그러나 iOS 8에서는 다음과 같은 이점을 얻을 수 있습니다.

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

포스트가 제공하는 솔루션을 사용해 보았습니다.

@property (strong,nonatomic)UIImagePickerController *controller;

_controller=[[UIImagePickerController alloc] init];
_controller.videoQuality=UIImagePickerControllerQualityTypeMedium;
_controller.delegate=(id)self;
_controller.sourceType=UIImagePickerControllerSourceTypeCamera;
_[self presentViewController:controller animated:YES completion:nil];

그리고 이건

...
controller.modalPresentationStyle=UIModalPresentationFullScreen;
or
controller.modalPresentationStyle=UIModalPresentationCurrentContext;
...

그리고 이건

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self presentViewController:controller animated:YES completion:nil];
});

그리고 이건

[self presentViewController:controller animated:YES completion:NULL];

그리고 이건

[self presentViewController:controller animated:YES completion:^{

}];

감 잡히는 게 없어요?

iOS 8.0의 합니다. 간단한 할 수 앱은 POC를 입니다.POC 어플리케이션에서는 이 어플리케이션의 프레젠테이션만 시도합니다.UIImagePickerController위에서 하는 것처럼요게다가 이미지 피커/카메라를 표시하는 것 외에 다른 패턴은 없는 것으로 알고 있습니다.애플의 Using UIImagePickerController 샘플 앱을 다운로드하여 실행할 수도 있습니다.그러면 개봉 즉시 동일한 오류가 발생합니다.

하지만 이 기능은 아직 유효합니다.경고/오류 이외에 앱 기능에 문제가 있습니까?

몇 시간 동안 이 문제로 고민하고 있었습니다.관련 토픽을 모두 읽어보니, 단말기의 프라이버시 설정에서 카메라로 앱에 접속할 수 없게 되어 에러가 발생하고 있는 것을 알 수 있었습니다.나는 카메라 접근을 거부한 적이 없고 어떻게 차단되었는지 모르겠지만 그게 문제였어!

위의 @greg의 답변에 대해 코멘트를 할 만한 평가점이 없기 때문에 여기에 제 의견을 추가하겠습니다.iPad와 iPhone의 Swift 프로젝트가 있습니다.메인 뷰 컨트롤러 안에 메서드가 있습니다(아래 관련 비트).전화로 테스트하면 모든 것이 정상적으로 동작하며 경고는 생성되지 않습니다.iPad에서 실행하면 모든 것이 제대로 작동하지만 보기 스냅샷에 대한 경고가 표시됩니다.하지만 흥미로운 점은 팝오버 컨트롤러를 사용하지 않고 iPad에서 실행하면 경고 없이 모든 것이 제대로 작동한다는 것입니다.안타깝게도, 애플은 카메라를 사용하지 않을 경우 이미지 피커를 아이패드의 팝오버 내에서 사용해야 한다고 규정하고 있다.

    dispatch_async(dispatch_get_main_queue(), {
        let imagePicker: UIImagePickerController = UIImagePickerController();
        imagePicker.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum;
        imagePicker.mediaTypes = [kUTTypeImage];
        imagePicker.allowsEditing = false;
        imagePicker.delegate = self;

        if(UIDevice.currentDevice().userInterfaceIdiom == .Pad){ // on a tablet, the image picker is supposed to be in a popover
            let popRect: CGRect = buttonRect;
            let popover: UIPopoverController = UIPopoverController(contentViewController: imagePicker);
            popover.presentPopoverFromRect(popRect, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Up, animated: true);
        }else{
            self.presentViewController(imagePicker, animated: true, completion: nil);
        }
    });

UIImagePickerController presentViewController:를 콜백에서 UIAlertView 대리인에게 호출한 후 이 문제가 발생했습니다.dispatch_async를 사용하여 presentViewController: call off current 실행 트레이스를 눌러 문제를 해결했습니다.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;

        if (buttonIndex == 1)
            imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        else
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController: imagePickerController
                           animated: YES
                         completion: nil];
    });
}

몇 가지 뷰를 애니메이션으로 만들 때 이 문제가 발생했는데, 앱이 백그라운드 모드로 전환되었다가 다시 돌아옵니다.플래그를 isActive로 설정하여 처리했습니다.에서 NO로 설정했습니다.

- (void)applicationWillResignActive:(UIApplication *)application

그리고 YES(네)

- (void)applicationDidBecomeActive:(UIApplication *)application

제 견해에 애니메이션을 주든 안 주든 상관없습니다.문제를 해결했다.

UIAlertControllerStyleAction과 함께 사용하였습니다.카메라로 사진을 찍거나 라이브러리에서 사진을 사용할 수 있는 옵션을 사용자에게 제공하는 시트입니다.

에러 메세지의 심볼적인 중단점을 시험해 보았다.

프레젠테이션 중 인턴이 UICollectionView를 사용했기 때문에 오류가 발생했음을 알 수 있습니다.

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

여기에 이미지 설명 입력

저는 발표하기 전에 프레임을 알기 쉽게 설정해서 고쳤습니다.

[alert setPreferredContentSize: alert.view.frame.size];

여기 오류 없이 작동하는 완전한 메토드가 있습니다.

-(void)showImageSourceAlertFromSender:(id)sender{
UIButton *senderButton = (UIButton*)sender;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction *action) {
                                                         [self takePhoto];
                                                     }];
UIAlertAction *libraryAction = [UIAlertAction actionWithTitle:@"Library" style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
                                                          [self selectPhotoFromLibraryFromSender:sender];
                                                      }];
[alert addAction:cameraAction];
[alert addAction:libraryAction];
alert.popoverPresentationController.delegate = self;
alert.popoverPresentationController.sourceRect = senderButton.frame;
alert.popoverPresentationController.sourceView = self.view;

[alert setPreferredContentSize: alert.view.frame.size];

[self presentViewController:alert animated:YES completion:^(){
}];}

뷰' 는 '뷰 스냅샷'을 수 .view뷰 컨트롤러를 표시하기 전에 속성을 지정합니다.이렇게 하면 보기가 로드되고 스냅샷을 생성하기 전에 iOS에서 렌더링할 수 있습니다.

UIAlertController *controller = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.popoverPresentationController.barButtonItem = (UIBarButtonItem *)sender;

... setup the UIAlertController ... 

[controller view]; // <--- Add to silence the warning.

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

이미지 캡처 후 검은색 미리보기에서 문제가 발생하는 경우 UIPicker Controller가 표시된 후 상태 표시줄을 숨기면 문제가 해결됩니다.

UIImagePickerControllerSourceType source = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ? UIImagePickerControllerSourceTypeCamera : UIImagePickerControllerSourceTypeSavedPhotosAlbum;
UIImagePickerController *cameraController = [[UIImagePickerController alloc] init];
        cameraController.delegate = self;
        cameraController.sourceType = source;
        cameraController.allowsEditing = YES;
        [self presentViewController:cameraController animated:YES completion:^{
            //iOS 8 bug.  the status bar will sometimes not be hidden after the camera is displayed, which causes the preview after an image is captured to be black
            if (source == UIImagePickerControllerSourceTypeCamera) {
                [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
            }
        }];

저는 같은 문제를 발견하고 모든 것을 시도했습니다.두 가지 앱이 있는데 하나는 오브젝트 C이고 다른 하나는 스위프트인데 둘 다 같은 문제가 있어요.디버거에 에러 메세지가 표시되고, 첫 번째 포토 후에 화면이 검게 된다.이는 iOS > = 8.0에서만 발생하며, 명백히 버그입니다.

나는 어려운 해결 방법을 찾았다.imagePicker로 카메라 컨트롤을 끕니다.showsCameraControls = false 및 누락된 버튼이 있는 overlayView를 만듭니다.이 방법을 설명하는 튜토리얼은 다양합니다.이상한 에러 메세지는 남지만, 적어도 화면은 검게 되지 않고, 동작하고 있는 앱이 있습니다.

내장 ImagePickerController 오류일 수 있습니다.코드는 동작하고 있습니다만, iPhone6 Plus로 크래쉬 하는 경우가 있습니다.

다른 답변에서 제시한 모든 해결책을 시도해 봤지만, 운이 없었습니다.JPSImagePickerController로 전환한 후 문제가 해결되었습니다.

다 해봤는데 카메라와 사진 라이브러리의 이미지 피커가 나오자마자 사라졌어요.다음 행(스위프트)으로 해결했습니다.

imagePicker.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

iOS 8.0의 버그에 불과하다고 생각합니다.위에서와 같이 UIImagePickerController를 표시하는 것 이외에는 할 수 없는 가장 단순한 POC 어플리케이션으로 재현할 수 있습니다.게다가 이미지 피커/카메라를 표시하는 것 외에 다른 패턴은 없는 것으로 알고 있습니다.애플의 Using UIImagePickerController 샘플 앱을 다운로드하여 실행할 수도 있습니다.그러면 개봉 즉시 동일한 오류가 발생합니다.

하지만 이 기능은 아직 유효합니다.경고/오류 이외에 앱 기능에 문제가 있습니까?

를 사용하고 있는 경우UIImagePickerController그러면 이 경고는 사라집니다.는 이 명령어의 결과를 사용하고 있지 않다고 가정합니다.UIImagePickerController를 인스턴스화할 경우UIImagePickerController기능 내에 있습니다.

이 방법을 호출한 것은 나에게 효과가 있었다.당신의 견해를 제시한 후에 배치하세요.

[yourViewBeingPresented.view layoutIfNeeded];

저도 같은 문제가 발생하여 카메라를 사용할 수 있는지 확인하고 해결했습니다.

BOOL cameraAvailableFlag = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    if (cameraAvailableFlag)
        [self performSelector:@selector(showcamera) withObject:nil afterDelay:0.3];

나는 이 문제에 대해 알게 되었다.카메라에 전화를 걸어 뷰를 공개하면 이 문제가 발생합니다.예를 들어 카메라를 호출하여 viewDidDispair 메서드에서 view를 0으로 설정하는 경우 카메라 이벤트에 대한 콜백이 없기 때문에 이 오류가 발생합니다.이 에러에 대해서도, 이 케이스에 대해 확인해 주세요.

카메라를 여는 동안 콘솔에 Bellow 메시지가 뜨는 것과 같은 버그가 발생했습니다.

렌더링되지 않은 보기를 스냅샷하면 빈 스냅샷이 생성됩니다.스냅샷 또는 화면 업데이트 후 스냅샷 전에 보기가 적어도 한 번 렌더링되었는지 확인하십시오.'

문제는 Info.plist file.it의 번들 표시명이 비어 있는 것입니다.어떻게 해서 앱명을 입력했는데 정상적으로 동작하고 있습니다.빈 번들 표시로 인해 카메라 권한 경보를 수신하지 못했습니다.번들 표시 name.it는 뷰의 렌더링을 차단했습니다.

문제는 뷰가 아니라 허락 없이 제시하는 것이었습니다.설정-->프라이버시-->카메라로 확인하실 수 있습니다.어플리케이션이 표시되지 않으면 같은 문제가 발생할 수 있습니다.

Phonegap을 사용하고 있는데, 에러 메시지를 검색하면 이 스레드가 계속 첫 번째 스레드로 나옵니다.

이 문제는 PNG로 이미지 타입을 정의함으로써 해결되었습니다.

encodingType : Camera.EncodingType.PNG

따라서 전체 행은 다음과 같습니다.

 navigator.camera.getPicture(successFunction, failFunction, { encodingType : Camera.EncodingType.PNG, correctOrientation:true, sourceType : Camera.PictureSourceType    .PHOTOLIBRARY, quality: 70, allowEdit : false , destinationType: Camera.DestinationType.DATA_URL});

마일리지는 다를 수 있지만, 그게 제겐 효과가 있었어요.

「」, 「」의 사용을 .drawViewHierarchyInRect:

신속:

extension UIImage{

    class func renderUIViewToImage(viewToBeRendered: UIView) -> UIImage
    {
        UIGraphicsBeginImageContextWithOptions(viewToBeRendered.bounds.size, true, 0.0)
        viewToBeRendered.drawViewHierarchyInRect(viewToBeRendered.bounds, afterScreenUpdates: true)
        viewToBeRendered.layer.renderInContext(UIGraphicsGetCurrentContext()!)

        let finalImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return finalImage
    }
}

목표-C:

- (UIImage *)snapshot:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0);
    [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

다음 항목도 참조해 주세요.

경우(7 및 는 ★★★★(XCode 7 † iOS 9)를 사용하고 .UINavigationController숨김이니까 '숨기다'를 돼요.UINavigationControllerDelegate메카라롤을을을을을여!And pickerControllerDelegate.self에러도 표시되지 않습니다.

언급URL : https://stackoverflow.com/questions/25884801/ios-8-snapshotting-a-view-that-has-not-been-rendered-results-in-an-empty-snapsho