首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AirPrint on iPad

AirPrint on iPad
EN

Stack Overflow用户
提问于 2015-04-30 02:49:12
回答 1查看 193关注 0票数 1

在我开始之前。是的,我看过苹果的文档,我在这里看到了所有类似的问题。

但出于某种原因,这些答案不适用于我。

我想从一个iPad打印。此代码适用于iPhone。当我按下iPad上的“打印”按钮时,屏幕上会出现一种灰色的外观,我可以按下,但什么也不会发生。

这是我的打印代码

代码语言:javascript
复制
  - (IBAction)printButton:(id)sender {
        NSMutableString *printFields = [NSMutableString     stringWithFormat:@"%@", _nameField.text];

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


    UIPrintInfo *printInfo = [UIPrintInfo printInfo];
    printInfo.outputType = UIPrintInfoOutputGeneral;
    printInfo.jobName = @"Printing sign up sheet.";
    pic.printInfo = printInfo;

    UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]initWithText:printFields];
    textFormatter.startPage = 0;
    textFormatter.contentInsets = UIEdgeInsetsMake(72, 72, 72, 72);
    textFormatter.maximumContentWidth = 6 * 72;
    pic.printFormatter = textFormatter;
    pic.showsPageRange = YES;


    void(^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
        if (!completed && error) {
            NSLog(@"Print error: %@", error);
        }
    };

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

}

如果我在iPhone上这样做,它就能正常工作。但出于某种原因,iPad遇到了麻烦。我真的不知道还能做什么。

如果我有10个代表点,我可以张贴我提到的灰色屏幕,但我不能这样做,对不起:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-30 02:59:05

谢谢@Paulw11 11,他告诉我我需要呈现打印按钮的fromRect

所以,我所做的是为我的按钮和礼物创造一个出口,它起作用了!

代码语言:javascript
复制
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [pic presentFromRect:self.printOutlet.frame inView:self.view animated:YES completionHandler:completionHandler];
    }
    else {
        [pic presentAnimated:YES completionHandler:completionHandler];
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29958162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档