我在这个极其奇怪的问题上苦苦挣扎了几天。这是用于初始化和呈现打印对话框的标准代码,在 iOS 9 之前它可以完美运行:
- (void)setupPrintingUIPrintInteractionController *)aPrintController
{
NSString *text = [self formattedHTMLforPrinting];
UIMarkupTextPrintFormatter *formatter = [[[UIMarkupTextPrintFormatter alloc] initWithMarkupText:text] autorelease];
aPrintController.printFormatter = formatter;
}
- (IBAction)printContentid)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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |