2

自从更新到最新的 XCode/Swift 2/iOS 9 后,我在尝试使用 UIPrintInteractionController 时不断收到警告。

这些警告仅在我打开“打印模拟器”时发生。我认为这是我的应用程序,所以我用一个 UIButton 制作了一个新的单视图应用程序,它执行非常简单的代码,但它仍然会生成警告。它发生在手机和 iPad 模拟器上

请帮忙。快把我逼疯了,谢谢大家

@IBAction func Clicked(sender: AnyObject) {

    let printController = UIPrintInteractionController.sharedPrintController()

    let printInfo = UIPrintInfo(dictionary:nil)
    printInfo.outputType = UIPrintInfoOutputType.General
    printInfo.jobName = "print Job"
    printController.printInfo = printInfo

    let formatter = UIMarkupTextPrintFormatter(markupText: "<b>Hello World</b>")
    formatter.contentInsets = UIEdgeInsets(top: 72, left: 72, bottom: 72, right: 72)
    printController.printFormatter = formatter

    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        printController.presentAnimated(false, completionHandler: nil)
    }else{
        printController.presentFromRect(view.frame, inView: view, animated: false, completionHandler: nil)
    }
}

以下是警告:

2015-09-29 18:58:19.748 MyApp[1608:527574] Unbalanced calls to begin/end appearance transitions for <UIViewController: 0x13d5c6170>.
2015-09-29 18:58:20.013 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:20.014 MyApp[1608:527574] 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.
2015-09-29 18:58:20.015 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6a1e10>, and it is attached to <UICollectionView: 0x13e063c00; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d5e7ef0>; layer = <CALayer: 0x13d507850>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x13d6a1e10>.
2015-09-29 18:58:20.015 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:20.026 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:20.026 MyApp[1608:527574] 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.
2015-09-29 18:58:20.027 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6a1e10>, and it is attached to <UICollectionView: 0x13e063c00; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d5e7ef0>; layer = <CALayer: 0x13d507850>; contentOffset: {0, 0}; contentSize: {320, 250}> collection view layout: <UICollectionViewFlowLayout: 0x13d6a1e10>.
2015-09-29 18:58:20.027 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:21.735 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:21.735 MyApp[1608:527574] 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.
2015-09-29 18:58:21.736 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6ba990>, and it is attached to <UICollectionView: 0x13e02c400; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d6809a0>; layer = <CALayer: 0x13d6aa750>; contentOffset: {0, 0}; contentSize: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0x13d6ba990>.
2015-09-29 18:58:21.736 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
2015-09-29 18:58:21.758 MyApp[1608:527574] the behavior of the UICollectionViewFlowLayout is not defined because:
2015-09-29 18:58:21.759 MyApp[1608:527574] 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.
2015-09-29 18:58:21.759 MyApp[1608:527574] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x13d6ba990>, and it is attached to <UICollectionView: 0x13e02c400; frame = (0 0; 320 250); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x13d6809a0>; layer = <CALayer: 0x13d6aa750>; contentOffset: {0, 0}; contentSize: {320, 250}> collection view layout: <UICollectionViewFlowLayout: 0x13d6ba990>.
2015-09-29 18:58:21.759 MyApp[1608:527574] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
4

3 回答 3

1

可能问题在于

printController.presentFromRect(view.frame, inView: view, animated: false, completionHandler: nil)

验证视图矩形presentFromRect

否则尝试

[printController presentAnimated:YES completionHandler:nil];

此解决方案删除了​​我的代码的警告,试试你的运气。

于 2016-03-03T13:22:59.763 回答
1

有同样的问题,使用委托方法解决了printInteractionControllerParentViewController(printInteractionController:)(感谢Balooka!)

所以:

  1. 在类头中:

    UIPrintInteractionControllerDelegate
    
  2. 某处:

    let printController = UIPrintInteractionController.sharedPrintController()
    
    printController.delegate = self
    
  3. 实现委托功能:

    func printInteractionControllerParentViewController(printInteractionController: UIPrintInteractionController) -> UIViewController {
        return self
    }
    
于 2016-09-14T10:17:40.253 回答
-1

当项目的尺寸UICollectionView不正确时,会打印您的问题中提到的警告。正如消息所述,aUICollectionViewCell的高度不能高于UICollectionView加上部分和内容插图的总和。

我遇到了你的问题,因为我遇到了同样的警告并且正在寻找它。就我而言,代码如下所示:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        let height = self.collectionView.frame.height
        let width = height * 0.75
        return CGSizeMake(width, height)
    }

这条线let height = self.collectionView.frame.height对我造成了警告。我什至将插图更改为零,但直到我使用let height = self.collectionView.frame.height * 0.75警告缩短高度并没有消失。

不确定这是否相关,因为您的代码没有显示任何 UICollectionView 相关信息,并且插图用于打印控制器。你找对地方了吗?

于 2015-11-13T02:34:12.327 回答