我为这个极其奇怪的问题苦苦挣扎了几天。下面是用于初始化和显示打印对话框的标准代码,它在 iOS 9 之前完美运行:
- (void)setupPrinting:(UIPrintInteractionController *)aPrintController
{
NSString *text = [self formattedHTMLforPrinting];
UIMarkupTextPrintFormatter *formatter = [[[UIMarkupTextPrintFormatter alloc] initWithMarkupText:text] autorelease];
aPrintController.printFormatter = formatter;
}
- (IBAction)printContent:(id)aSender {
if ([UIPrintInteractionController isPrintingAvailable]) {
UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
printController.delegate = self;
[self setupPrinting:printController];
//tried different ways to present print controller
// [printController presentAnimated:NO completionHandler:nil];
// [printController presentFromRect:self.view.bounds inView:self.view animated:YES
//these two lines are just to make sure printButton is not nil
self.printButton.layer.borderColor = [UIColor redColor].CGColor;
self.printButton.layer.borderWidth = 1.0;
[printController presentFromRect:self.printButton.bounds inView:self.printButton animated:YES
completionHandler:^(UIPrintInteractionController *aPrintController, BOOL aCompleted, NSError *anError)
{
NSLog(@"printing is done with error: %@", anError);
}];
}
}
在 iOS 9 上,打印对话框显示错误且无法关闭在模态视图外点击没有效果 - 应用程序变得无响应。
最佳答案
发生的事情是模式窗口剪裁了取消和打印按钮,使您停留在该 View 中。如果有人遇到类似问题,请检查您是否在 UINavigationBar
类上设置了固定宽度。更新后,按钮应返回模式。
关于iOS 9 : UIPrintInteractionController presentation issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33690154/