【问题标题】:UIPrintInteractionController appends a blank page when the orientation is set to Landscape当方向设置为横向时,UIPrintInteractionController 会附加一个空白页
【发布时间】:2015-11-26 06:34:02
【问题描述】:

我正在尝试使用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 页来解决此问题,但到目前为止我无法完成其中任何一个。有什么想法吗?

【问题讨论】:

    标签: objective-c iphone swift uiprintinteractioncntrler uiprintpagerenderer


    【解决方案1】:

    看来我可以解决这个问题,不是直接为UIPrintInteractionController 设置printFormatter,而是创建一个UIPrintPageRenderer,然后将我的格式化程序附加到渲染器,然后再将其设置为UIPrintInteractionController

    解决办法如下:

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

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 1970-01-01
      • 2013-10-08
      • 2017-02-11
      • 2015-03-20
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多