【发布时间】:2015-04-28 01:21:15
【问题描述】:
我正在尝试从可在 iPhone 和 iPad 上运行的应用程序进行打印。 iPhone部分打印没有问题。但是,每当我点击打印按钮时,我都不会弹出允许我选择打印机并发送作业的弹出窗口。
调用此视图的视图是导航控制器中的常规 UIView(如果有任何影响)。
通过 IBAction 调用它的按钮是分段控件的一部分,因为这似乎是我在导航栏中获得除后退按钮之外的三个按钮的最佳方式。我不认为它是按钮,因为正如我所说,它适用于 iPhone 版本。
我已经证实它至少认为它正在呈现。我为图片生成了高度、宽度和原点,但我看不到它。任何帮助都会非常棒,因为这是此应用程序的最后一块拼图。
谢谢!
- (void)printStory
{
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = @"My Great Prompt";
pic.printInfo = printInfo;
NSString *msgBody = [NSString stringWithFormat:@"%@%@%@", self.summaryLabel.text, @"\n\n", self.storyEditorTextView.text];
UISimpleTextPrintFormatter *textFormatter = [[UISimpleTextPrintFormatter alloc]
initWithText:msgBody];
textFormatter.startPage = 0;
textFormatter.contentInsets = UIEdgeInsetsMake(72.0, 72.0, 72.0, 72.0); // 1 inch margins
textFormatter.maximumContentWidth = 6 * 72.0;
pic.printFormatter = textFormatter;
pic.showsPageRange = YES;
void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) =
^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"Printing could not complete because of error: %@", error);
}
};
if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[pic presentFromRect:self.view.frame
inView:self.view
animated:YES
completionHandler:completionHandler];
}
else {
[pic presentAnimated:YES completionHandler:completionHandler];
}
}
【问题讨论】:
-
尝试传递一个较小的
rect。你不应该传入一个填满屏幕的矩形。 -
谢谢。这似乎起到了作用。不过,我似乎无法将您的评论标记为答案。
-
我发表了我的评论作为更彻底的答案。
标签: ios objective-c iphone ipad