当方向设置为“横向”时,UIPrintInteractionController会追加空白页

肘的

我尝试使用发送字符串到打印机,UIMarkupTextPrintFormatter并且当我不更改页面方向时一切都很好-默认情况下设置为纵向。

人像打印预览

但是,当我将页面方向设置为横向时,一个空白页面会附加到渲染的输出中,就像边距超出了第一页一样。

风景打印预览

这是我的打印代码:

let printController = UIPrintInteractionController.sharedPrintController()

let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = "Print Job"
printInfo.orientation = .Landscape
printController.printInfo = printInfo

let formatter = UIMarkupTextPrintFormatter(markupText: "Welcome")
formatter.contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
printController.printFormatter = formatter

printController.presentAnimated(true, completionHandler: nil)

要注意的另一件事是,当页面设置为横向时,Xcode会记录一些与自动布局有关的错误。

the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa066097850>, and it is attached to <UICollectionView: 0x7fa06687f800; frame = (0 0; 375 313.5); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fa066095e90>; layer = <CALayer: 0x7fa066098b30>; contentOffset: {0, 0}; contentSize: {666, 313.5}> collection view layout: <UICollectionViewFlowLayout: 0x7fa066097850>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa066097850>, and it is attached to <UICollectionView: 0x7fa06687f800; frame = (0 0; 375 313.5); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fa066095e90>; layer = <CALayer: 0x7fa066098b30>; contentOffset: {0, 0}; contentSize: {666, 313.5}> collection view layout: <UICollectionViewFlowLayout: 0x7fa066097850>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x7fa066085830>.
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa063c55130>, and it is attached to <UICollectionView: 0x7fa064043000; frame = (0 0; 375 313.5); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fa063c4a720>; layer = <CALayer: 0x7fa063c26e60>; contentOffset: {0, 0}; contentSize: {666, 313.5}> collection view layout: <UICollectionViewFlowLayout: 0x7fa063c55130>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7fa063c55130>, and it is attached to <UICollectionView: 0x7fa064043000; frame = (0 0; 375 313.5); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x7fa063c4a720>; layer = <CALayer: 0x7fa063c26e60>; contentOffset: {0, 0}; contentSize: {666, 313.5}> collection view layout: <UICollectionViewFlowLayout: 0x7fa063c55130>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

我尝试仅打印第一页,但是找不到有关设置页面范围的任何信息,可以设置UIMarkupTextPrintFormatter一个startPage变量,但是设置它并不算运,即使将其设置为第二页,它也会呈现出原来的样子。没有设置任何东西。

我可以通过摆脱空白页或将打印范围设置为仅第1页来解决此问题,但到目前为止,我什么都做不完。有任何想法吗?

肘的

看来我可以通过以下方法解决此问题:不是直接设置printFormatterfor UIPrintInteractionController,而是创建一个UIPrintPageRenderer,然后将其格式化程序附加到渲染器,然后再将其设置为UIPrintInteractionController

解决方法如下:

// printController.printFormatter = formatter // cancelled
let printRenderer = UIPrintPageRenderer()
printRenderer.addPrintFormatter(formatter, startingAtPageAtIndex: 0)
printController.printPageRenderer = printRenderer

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

当方向设置为“横向”时,UIPrintInteractionController会追加空白页

来自分类Dev

运行构建时为空白页

来自分类Dev

尝试同时设置Apache和Django时为空白页

来自分类Dev

没有设置断点时,Puppeteer呈现空白页

来自分类Dev

尝试访问phpmyadmin时为空白页

来自分类Dev

使用TuesPechkin转换为PDF时为空白页

来自分类Dev

尝试访问phpmyadmin时为空白页

来自分类Dev

使用CGPDFContextCreateWithURL时,PDF为空白页

来自分类Dev

使用不同方向时,mPDF 在 TOC 后创建空白页

来自分类Dev

用PHP MySQL创建动态页面时为空白页

来自分类Dev

呼叫表单帮助程序CodeIgniter时为空白页

来自分类Dev

SSRS隐藏列会创建额外的空白页

来自分类Dev

数组分页会创建多余的空白页

来自分类Dev

UIPageViewController空白页

来自分类Dev

Django空白页

来自分类Dev

将打印方向设置为横向

来自分类Dev

带有“ NPM开始”的Gulp会导致空白页上显示以下文本:本地测试时无法GET /

来自分类Dev

Sidekiq网站返回正文为空的空白页

来自分类Dev

AngularJS $ stateProvider URL结果为空白页

来自分类Dev

提交表单时为什么会出现空白页?

来自分类Dev

在Laravel中上传图像时获取空白页

来自分类Dev

HTTPS域正常时HTTPS域显示空白页

来自分类Dev

链接XSL时XML显示空白页

来自分类Dev

添加反引号代码块时的Octopress空白页

来自分类Dev

WebView打开付款站点时显示空白页-Lollipop

来自分类Dev

运行表单脚本时,php pdo空白页

来自分类Dev

打印时还有一个空白页

来自分类Dev

使用挂钩时组件呈现为空白页

来自分类Dev

IIS返回401时提供空白页