37

我正在使用UIPrintInteractionController从矩形呈现它。

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

比我设置页数(>1)并选择打印机。在设备旋转之前我打电话

[controller dismissAnimated:animated];

根据 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.

当我UIPrintInteractionController在旋转后呈现时,打印份数设置回 1(如在初始视图中),而打印机保持选中状态。UIPrintInfo 的 Ivar _copies 是私有的,因此我无法在轮换期间获取并存储它。

旋转后如何恢复打印页数?

4

4 回答 4

1

抱歉,这似乎是一个明显的问题,但您是否将其称为代表?

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
controller.delegate = self;
于 2014-07-17T08:05:33.770 回答
1
[printInfo setValue:[NSNumber numberWithInteger:numberFile] forKey:@"copies"]

您可以设置和设置@"copies"UIPrintInfo

于 2016-07-08T04:56:02.457 回答
-1
- (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

}
于 2014-10-09T09:51:03.193 回答
-1

如果我理解正确,您真正需要的是如何在方向更改之前和之后运行代码:

迅速:

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 
    })

}

对象 C 文档:

于 2017-07-22T13:24:46.870 回答