【问题标题】:UIPrintInteractionController not displaying in iPadUIPrintInteractionController 未在 iPad 中显示
【发布时间】:2015-04-28 01:21:15
【问题描述】:

我正在尝试从可在 iPhone 和 iPad 上运行的应用程序进行打印。 iPhone部分打印没有问题。但是,每当我点击打印按钮时,我都不会弹出允许我选择打印机并发送作业的弹出窗口。

调用此视图的视图是导航控制器中的常规 UIView(如果有任何影响)。

通过 IBAction 调用它的按钮是分段控件的一部分,因为这似乎是我在导航栏中获得除后退按钮之外的三个按钮的最佳方式。我不认为它是按钮,因为正如我所说,它适用于 iPhone 版本。

我已经证实它至少认为它正在呈现。我为图片生成了高度、宽度和原点,但我看不到它。任何帮助都会非常棒,因为这是此应用程序的最后一块拼图。

谢谢!

- (void)printStory
{
    UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
    pic.delegate = self;

    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"My Great Prompt";
    pic.printInfo = printInfo;

    NSString *msgBody = [NSString stringWithFormat:@"%@%@%@", self.summaryLabel.text, @"\n\n", self.storyEditorTextView.text];


    UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]
                                                 initWithText:msgBody];
    textFormatter.startPage = 0;
    textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
    textFormatter.maximumContentWidth = 6 * 72.0;
    pic.printFormatter = textFormatter;
    pic.showsPageRange = YES;

    void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
    ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"Printing could not complete because of error: %@", error);
        }
    };

    if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        [pic presentFromRect:self.view.frame
                      inView:self.view
                    animated:YES
           completionHandler:completionHandler];
        }
    else {
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
}

【问题讨论】:

  • 尝试传递一个较小的rect。你不应该传入一个填满屏幕的矩形。
  • 谢谢。这似乎起到了作用。不过,我似乎无法将您的评论标记为答案。
  • 我发表了我的评论作为更彻底的答案。

标签: ios objective-c iphone ipad


【解决方案1】:

您需要传入一个较小的rect。不能传入视图控制器视图的rect。弹出框显示在传入的矩形周围。如果矩形填满屏幕,则弹出框将显示在屏幕之外。矩形应该是相对较小的东西,例如按钮的矩形或其他小视图,以便弹出框的指针可以触摸矩形的边缘并且弹出框的其余部分可以适合屏幕。

【讨论】:

  • 谢谢。这完全解决了我的问题。我唯一的另一个问题是它在我打印时崩溃,但仅在模拟器中。 iPad打印实际上很好。再次感谢您的帮助。
【解决方案2】:

请将以下代码移至您的 .h 文件中。

UIPrintInteractionController *pic;

因为当方法完成时,图片对象将被释放,所以可能是导致问题的原因。

您传递的矩形应该是您使用的按钮或分段的位置。

希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 2012-05-29
    相关资源
    最近更新 更多