gpt4 book ai didi

ios - iPad 中的 UIPrintInteractionController 给我两个警告

转载 作者:可可西里 更新时间:2023-11-01 03:27:16 30 4
gpt4 key购买 nike

我正在使用代码在我的应用程序中获取 Airprint,以将当前 View 打印为图像。Airprint 对话框弹出,但在日志屏幕中显示了两个警告:

1) 警告:在 iPad 上调用 -[UIPrintInteractionController presentAnimated:completionHandler:]找不到 PDF 标题:找不到“%PDF”。

2)[UIPopoverController_commonPresentPopoverFromRect:inView:permittedArrowDirections:animated:]:传入此方法的矩形必须具有非零宽度和高度。这将是 future 版本中的一个异常(exception)。

我已经在网上搜索过,但发现所有解决方案都为常规的矩形按钮提供

我这里用的是分段控件,不知道这种情况下这个控件怎么用

这里是段控制代码:

- (IBAction)legalSegment:(id)sender {


switch (((UISegmentedControl *)sender).selectedSegmentIndex) {
case 0:
{
[self printItem];
break;
}
}

这是 printItem 方法:

-(void)printItem {
CGRect rect = CGRectMake(0, 0, 768, 1004);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIPrintInteractionController* pic = [UIPrintInteractionController sharedPrintController];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
if (pic && [UIPrintInteractionController canPrintData:imageData])
{
pic.delegate = self;
UIPrintInfo* printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputPhoto;
printInfo.jobName = @"PrintingImage";
printInfo.duplex = UIPrintInfoDuplexLongEdge;
pic.printInfo = printInfo;
pic.showsPageRange = YES;
pic.printingItem = imageData;

void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if (!completed && error) {
NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
}
};

[pic presentAnimated:YES completionHandler:completionHandler];
}
}

任何帮助都会很棒。提前致谢!

最佳答案

在 iPad 上,您应该使用 Controller 提供的 popover API。文档中提到了它。

presentAnimated:completionHandler:

Presents the iPhone printing user interface in a sheet that can be animated to slide up from the bottom of the screen.

presentFromBarButtonItem:animated:completionHandler:

Presents the iPad printing user interface in a popover view that can be animated from a bar-button item.

presentFromRect:inView:animated:completionHandler:

Presents the iPad printing user interface in a popover view that can be animated from any area in a view.

您应该在相应的设备类型上使用正确的方法。

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[pic presentFromRect:self.view.frame inView:self.view animated:YES completionHandler:completionHandler];
}
else {
[pic presentAnimated:YES completionHandler:completionHandler];
}

您应该为弹出窗口显示使用适当的参数。

关于ios - iPad 中的 UIPrintInteractionController 给我两个警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20916628/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com