2014-10-17 1 views
1

AirPrint를 사용하여 이미지를 인쇄하려면 UIPrintInteractionController의 인스턴스를 표시하려고합니다. 처음에는 아무 일도 일어나지 않았지만 대리자 메서드 printInteractionControllerDidPresentPrinterOptions: 내에서 self.presentedViewController을 사용하여 "제시된"인쇄 상호 작용 컨트롤러에 대한 정보를 얻었습니다. 그것이 폭이 19.000이고 높이가 0.000 인 것으로 밝혀졌습니다 ... 실제로 프레임 워크에서 자동으로 생성 된 이후에 실제로 표시되기 전에 viewcontroller에 액세스하는 방법이없는 것처럼 보입니다. 프레임 포스트 프레 젠 테이션을 성공적으로 수정할 수 있습니다. 다른 누구든지이 문제가 발생하거나 해결 방법을 찾았습니까?iOS 8 인쇄 상호 작용 컨트롤러의 높이가 iPad에서 0입니다.

- (void)printBadgeImage:(UIImage *)image { 

    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = BADGE_PRINT_JOB; 
    printInfo.duplex = UIPrintInfoDuplexLongEdge; 
    pic.printInfo = printInfo; 
    pic.printingItem = image; 
    pic.delegate = self; 

    UIPrintInteractionCompletionHandler completionHandler = 
    ^(UIPrintInteractionController *printController, 
     BOOL completed, 
     NSError *error) { 

     if (completed) { 

      NSLog(@"Print job completed"); 

     } else if (!completed && error) { 

      NSLog(@"Print job error"); 
      NSString *errorString = [NSString stringWithFormat:@"An error occured while printing: %@", error]; 
      UIAlertView *alert = [[DOSimpleAlertView alloc] initWithTitle:@"Error" 
                    message:errorString]; 

      [alert show]; 

     } else { 

      NSLog(@"Print job incomplete without error"); 
     } 
    }; 

    [pic presentFromRect:self.view.frame 
        inView:self.view 
       animated:YES 
     completionHandler:completionHandler]; 

} 

- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController { 

    NSLog(@"Did present"); 
    // following printed <UIPrintInteractionController: 0x145d1a30> 
    NSLog(@"The Print Interaction Controller: %@", printInteractionController); 
    // following printed <UINavigationController: 0x145d3840> 
    NSLog(@"The presented view: %@", self.presentedViewController); 
    UIViewController *presented = self.presentedViewController; 
    // following printed 19.000000 
    NSLog(@"Presented view width: %f", presented.view.frame.size.width); 
    // following printed 0.000000 
    NSLog(@"Presented view height: %f", presented.view.frame.size.height); 
    // following printed 0.000000 
    NSLog(@"Presented view x: %f", presented.view.frame.origin.x); 
    // following printed 0.000000 
    NSLog(@"Presented view y: %f", presented.view.frame.origin.y); 

답변

0

이미지를 인쇄하는 앱이 있지만 오랫동안 코드를 보지 않았습니다. 그러나 여기에 광고문이 있습니다. 도움이되기를 바랍니다.

NSData *moneyData = UIImageJPEGRepresentation(image, 1.0); 
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController]; 
if(pic && [UIPrintInteractionController canPrintData: moneyData]) { 

    pic.delegate = self; 

    UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 
    printInfo.outputType = UIPrintInfoOutputGeneral; 
    printInfo.jobName = @"MONEY"; 
    printInfo.duplex = UIPrintInfoDuplexLongEdge; 
    pic.printInfo = printInfo; 
    pic.showsPageRange = YES; 
    pic.printingItem = moneyData; 

    [pic presentFromBarButtonItem:self.printButton animated:YES completionHandler:nil]; 
} 

내가 기억하는 경우 당신이 그것을 선물하는 방법에 대해 특별한 것이 있습니다. 내 것과 같은 막대 버튼 항목에서 시도 할 수 있습니다.