2012-11-05 12 views
24

Sto usando UIPrintInteractionController presentandolo da rect.Rifiuto di UIPrintInteractionController

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; 
// than set printing settings 
... 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    [controller presentFromRect:rect inView:view animated:YES completionHandler:completionHandler]; 

Poi ho impostato il numero di pagine (> 1) e selezionato una stampante. Prima rotazione dispositivi chiamo

[controller dismissAnimated:animated];

secondo la documentazione Xcode: You should dismiss the printing options when they are presented in a sheet or animated from a rectangle and the user changes the orientation of the device.

Quando sono presenti UIPrintInteractionController dopo la rotazione, il numero di copie di stampa è arretrato a 1 (come nella vista iniziale), mentre la stampante rimane selezionata. Ivar _copies di UIPrintInfo è privato, quindi non riesco ad ottenerlo e memorizzarlo durante la rotazione.

Come è possibile ripristinare il numero di pagine di stampa dopo la rotazione?

+0

perché lo si disattiva a rotazione? – NeverBe

+4

@NeverBe perché Apple consiglia di farlo nella descrizione del metodo 'dismissAnimated:' della classe 'UIPrintInteractionController'. "È necessario eliminare le opzioni di stampa quando vengono presentate in un foglio o animate da un rettangolo e l'utente cambia l'orientamento del dispositivo." e "Dovresti quindi presentare nuovamente le opzioni di stampa una volta che il nuovo orientamento diventa effettivo." – Anastasia

+1

Ecco un [collegamento a 'UIPrintInteractionController' class] (https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPrintInteractionController_Class/Reference/Reference.html). – Anastasia

risposta

0

Spiacente, questa può sembrare una domanda ovvia, ma l'hai chiamata come delegata?

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; 
controller.delegate = self; 
-2
- (void)printImage:(id)sender { 
    // Obtain the shared UIPrintInteractionController 
    UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController]; 
    if(!controller){ 
    NSLog(@"Couldn't get shared UIPrintInteractionController!"); 
    return; 
    } 

    // We need a completion handler block for printing. 
    UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) { 
    if(completed && error) 
     NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code); 
    }; 

     // Obtain a printInfo so that we can set our printing defaults. 
    for(int i=0;i<[paths count];i++) 
    { 
     NSString *strFilePath = [paths objectAtIndex:i]; 
     NSLog(@"@ strFilePath is %@", strFilePath); 
     NSData *data = [NSData dataWithContentsOfFile:strFilePath]; 
     if(data) 
     { 
      image = [UIImage imageWithData:data]; 
      // [arrayOfImages addObject:image]; 
       NSLog(@"@ image is %@", image); 
      UIPrintInfo *printInfo = [UIPrintInfo printInfo]; 

      // This application prints photos. UIKit will pick a paper size and print 
      // quality appropriate for this content type. 
      printInfo.outputType = UIPrintInfoOutputPhoto; 
      // The path to the image may or may not be a good name for our print job 


      printInfo.jobName = @"PNg"; 
      NSLog(@"@ imageURL is %@", printInfo.jobName); 
      // printInfo.jobName 


      if(!controller.printingItems && image.size.width > image.size.height) 
       printInfo.orientation = UIPrintInfoOrientationLandscape; 

      // Use this printInfo for this print job. 
      controller.printInfo = printInfo; 


      controller.printingItems = nil; 

     } 
    } 





#if DIRECT_SUBMISSION 
    // Use the URL of the image asset. 
    if(self.imageURL && [UIPrintInteractionController canPrintURL:self.imageURL]) 
     controller.printingItem = self.imageURL; 
#endif 

    // If we aren't doing direct submission of the image or for some reason we don't 
    // have an ALAsset or URL for our image, we'll draw it instead. 
    if(!controller.printingItems){ 
    // Create an instance of our PrintPhotoPageRenderer class for use as the 
    // printPageRenderer for the print job. 
    PrintPhotoPageRenderer *pageRenderer = [[PrintPhotoPageRenderer alloc]init]; 

    pageRenderer.imageToPrint = image; 
    controller.printPageRenderer = pageRenderer; 
    [pageRenderer release]; 
    } 


    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    [controller presentFromBarButtonItem:self.printButton animated:YES completionHandler:completionHandler]; // iPad 
    }else 
    [controller presentAnimated:YES completionHandler:completionHandler]; // iPhone 

} 
+0

Ulteriori spiegazioni per favore. Cos'hai fatto? Perché? Dove sono le linee chiave nel tuo codice? – TobiMcNamobi

0
[printInfo setValue:[NSNumber numberWithInteger:numberFile] forKey:@"copies"] 

È possibile impostare e impostare @"copies" di UIPrintInfo

0

Se ho capito bene, che cosa si ha realmente bisogno è come eseguire il codice prima e dopo le modifiche di orientamento:

In swift:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 
    super.viewWillTransition(to: size, with: coordinator) 

    //code goes here to run before orientation change 

    coordinator.animate(alongsideTransition: nil, completion: { 
     _ in 

     //code goes here to run after orientation change 
    }) 

} 

Obj C docs:

Problemi correlati