在我开始之前。是的,我看过苹果的文档,我在这里看到了所有类似的问题。
但出于某种原因,这些答案不适用于我。
我想从一个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个代表点,我可以张贴我提到的灰色屏幕,但我不能这样做,对不起:
发布于 2015-04-30 02:59:05
谢谢@Paulw11 11,他告诉我我需要呈现打印按钮的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];
}https://stackoverflow.com/questions/29958162
复制相似问题