iPad上的AirPrint

问题描述:

开始之前。是的,我查看了苹果的文档,我也看到了类似的问题。iPad上的AirPrint

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

我正在从iPad打印。此代码适用于iPhone。当我按下打印按钮时,在iPad上,屏幕变灰,看起来可以按下,但没有任何反应。

这里是我的打印

- (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个代表处点,我将能够张贴灰色屏幕,我提到过,但我不能这样做,对不起:(

+0

您呈现fromRect'self.view.frame'它会显示你的视图之外的对话框(屏幕外)。你应该出现在你的Rect中r打印按钮。 – Paulw11

+0

@ Paulw11我该怎么做? **我懂了!**谢谢保罗! – Michael

+0

而不是说'fromRect:self.view.frame'说'fromRect:sender.frame'将'sender'从'id'改为'UIButton *' – Paulw11

谢谢@ Paulw11谁给我看,我需要我的打印按钮的存在fromRect

所以我所做的就是创建我的按钮,然后从出口目前,它的工作!

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