1
我想展示一个UIPrintInteractionController的实例来使用AirPrint来打印图像。起初,它好像什么都没有发生,但在委托方法printInteractionControllerDidPresentPrinterOptions:
内部,我使用self.presentedViewController
来获取有关假定的“呈现”打印交互控制器的信息。发现它的宽度为19.000,高度为0.000 ...似乎没有办法在实际显示之前访问视图控制器,因为它是在框架中自动生成的,而且我还没有能够成功修改其框架展示后。其他人遇到此问题和/或找到解决办法?iOS 8打印交互控制器在iPad上有0高度
- (void)printBadgeImage:(UIImage *)image {
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = BADGE_PRINT_JOB;
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.printingItem = image;
pic.delegate = self;
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *printController,
BOOL completed,
NSError *error) {
if (completed) {
NSLog(@"Print job completed");
} else if (!completed && error) {
NSLog(@"Print job error");
NSString *errorString = [NSString stringWithFormat:@"An error occured while printing: %@", error];
UIAlertView *alert = [[DOSimpleAlertView alloc] initWithTitle:@"Error"
message:errorString];
[alert show];
} else {
NSLog(@"Print job incomplete without error");
}
};
[pic presentFromRect:self.view.frame
inView:self.view
animated:YES
completionHandler:completionHandler];
}
- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController {
NSLog(@"Did present");
// following printed <UIPrintInteractionController: 0x145d1a30>
NSLog(@"The Print Interaction Controller: %@", printInteractionController);
// following printed <UINavigationController: 0x145d3840>
NSLog(@"The presented view: %@", self.presentedViewController);
UIViewController *presented = self.presentedViewController;
// following printed 19.000000
NSLog(@"Presented view width: %f", presented.view.frame.size.width);
// following printed 0.000000
NSLog(@"Presented view height: %f", presented.view.frame.size.height);
// following printed 0.000000
NSLog(@"Presented view x: %f", presented.view.frame.origin.x);
// following printed 0.000000
NSLog(@"Presented view y: %f", presented.view.frame.origin.y);