【问题标题】:Dismissing of UIPrintInteractionController解除 UIPrintInteractionController
【发布时间】:2012-11-05 15:27:57
【问题描述】:

我正在使用 UIPrintInteractionController 从 rect 呈现它。

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 是私有的,因此在轮换期间我无法获取和存储。

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

【问题讨论】:

  • 你为什么在轮换时解雇它?
  • @NeverBe 因为 Apple 建议在 UIPrintInteractionController 类的 dismissAnimated: 方法的描述中这样做。 “当打印选项以表格形式呈现或从矩形动画并且用户更改设备的方向时,您应该关闭打印选项。”和“一旦新方向生效,您应该再次显示打印选项。”
  • 有没有找到答案?
  • @RyanPoolos 还是没有,你有什么想法吗?

标签: ios ipad uiprintinteractioncntrler


【解决方案1】:

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

UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
controller.delegate = self;

【讨论】:

    【解决方案2】:
    [printInfo setValue:[NSNumber numberWithInteger:numberFile] forKey:@"copies"]
    

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

    【讨论】:

      【解决方案3】:
      - (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
      
      }
      

      【讨论】:

      • 请多解释。你做了什么?为什么?代码中的关键行在哪里?
      【解决方案4】:

      如果我理解正确的话,你真正需要的是如何在方向改变前后运行代码:

      迅速:

      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:

      【讨论】:

        猜你喜欢
        • 2012-06-13
        • 2012-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多